Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

Add custom content to the system

Go to End

17 Posts   5656 Views


Community Member, 501 Posts

29 September 2007 at 8:10pm

Ok, but what about properties that aren't set through the object?


$tip->ClassName = "Tip";
$tip->Status = "Published";
$tip->Viewers = "Anyone";
$tip->ParentID = 2;
$tip->MenuTitle ...

aren't set by the data in the form so I have to do it manually.

I know I can do $form->saveInto($myObject) but that's the same thing I'm doing here manually,no?

So you say all I need to get it work is


So I can lose $tip->writeToStage("Stage"); and $tip->publish("Stage", "Live"); ?


Community Member, 501 Posts

29 September 2007 at 8:18pm

Edited: 29/09/2007 8:52pm


FATAL ERROR: Missing argument 1 for Versioned::publish()

Publish does need an argument...

So for all clarity: my main problem is getting my Tip, that extends Page, into SiteTree and Page.
When doing this like I have been doing, it throws a fatal error but it looks like it IS inserted into SiteTree_Live and Tip_Live but NOT in SiteTree and Tip as it should. In these latter two I can see new data in the database table but all the values are set to NULL or the default field value.

Doing just $tip->publish() does the same thing but just throws a different fatal error.

And what is the difference between:

$tip = Object::create('Tip');
$tip = new Tip();


Forum Moderator, 801 Posts

30 September 2007 at 12:26am

i'm not sure what exact code you need, but you might wanna have a look at LeftAndMain->save() for some pointers (this is where the main page-saving in the cms happends).

> $tip = Object::create('Tip');
this is the default notation for any core/module-code where functionality might need to be extended without file-modifications: by setting Object::useCustomClass('Tip','MySpecialTip') you can force the creation of your subclass. see


Community Member, 501 Posts

30 September 2007 at 12:48am

Edited: 30/09/2007 1:22am

I basically just need to code that comes after


What I'm noticing when only doing ->write() is that it's inserted in every _Live-table but not in the normal tables, except for SiteTree where it takes the default values.

So I need the code that publishes my tip, that makes sure that tip is part of both SiteTree and Sitetree_Live, Page AND Page_Live...

The tip is a page. So when writing it from the frontend it should be seen in the cms too and be published as a page on the livesite..

What I'm actually doing is providing a way for members to insert a new 'page' (tip) through the frontend instead of actually entering the cms...

Basically the same question that mednezz asked initially.

I know it's something with the publish-function.. but I need details.

I'll have a search for the LeftAndMain->save() - thing...


Community Member, 501 Posts

30 September 2007 at 3:52am

It looks like I solved it (not gonna jump too high though.. still need some more testing)

Anyway, all I needed was:

$tip->publish("Live", "Stage");

instead of

$tip->publish("Stage", "Live");

Weird... very weird.. one should think you have to publish from the stage to the live but oddly enough it is the other way around. I don't understand the why of this. In the blog-code it is from stage to live...

Probably noone has an answer to this??


Forum Moderator, 922 Posts

30 September 2007 at 5:23pm

Edited: 30/09/2007 5:26pm

If the blog code has that, then it's probably good to do it the same way? Of course there's probably multiple ways to do it, but the 'most ideal' solution and an example would be helpful to know.

Unfortunately I don't know the answer myself as there's many ways to do write/write to stage/write to publish, but I'm unsure what's the best way to do it. However, I can guess that ->publish('Live', 'Stage') is how it is, because the second argument may have been added at an extended date after the method was first created, perhaps? Also, are you actually 'publishing' the page to the 'Stage' site? Another oddity. ;-)

@Ingo: You seem to have a grasp on this. Any ideas on a 'best practise' here? Would be useful for others like myself when we'll be using it in future. A definitive answer can then be added to the SilverStripe documentation. :-)



Community Member, 501 Posts

30 September 2007 at 8:42pm

All I'm doing is grabbing the data from my form

$tip = Object::create('Tip');

and then doing

$tip->ClassName = "Tip";
$tip->Status = "Published";
$tip->Viewers = "Anyone";
$tip->ViewersGroup = 1;
$tip->ParentID = 2;

$tip->publish("Live", "Stage");

If I do it the other way around like in the blog then I get fatal errors.

No I am not publishing it to the 'Stage' ... as far as I know. I did try doing

$tip->publish("Stage", "Live");

But that also gave a fatal error. (Notice I publish from stage to live there, what seems the most logical after writing to stage..)

I believe a very clear example of how this should be done with decent explanation would be great. It's working now but I'm not sure why.

Looks like when you do a 'write' on the 'frontend', which can be seen as the live site, things are written to the _Live tables. In that way it makes sense that you still have to publish from the live site to the stage site. That is what I'm making of it right now.

There must be some of you guys who know how this works?


Community Member, 23 Posts

1 October 2007 at 2:07am


It works quite alright like this. Only for some kind of reason sometimes it creates 2 entries.

Heres my code :

// create the new member
$vacature = Object::create('VacaturePage');

$vacature->URLSegment = SiteTree::generateURLSegment($vacature->VacatureTitle);
$vacature->MenuTitle = SiteTree::generateURLSegment($vacature->VacatureTitle);
$vacature->Title = $vacature->VacatureTitle;
$vacature->ShowInMenus = 0;

$member = $this->Member();
$vacature->FotoID = $member->AvatarID;
$vacature->Bedrijfsnaam = $member->CompanyName;

$vacature->Status = "Published";
$vacature->publish("Live", "Stage");

$data = array(
"Title" => "Vacature plaatsen",
"Form" => $form
return $this->customise($data)->renderWith(array('MyAccountVacatureBetalen', 'Page'));

so sometimes i het 2 "vacature"'s

strange huh.. any ideas?