21278 Posts in 5728 Topics by 2599 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 533 Views |
-
Adding page from controller

29 January 2010 at 5:46am
Hi,
I'm trying to add a page to the Sitetree from a controller.
I have ProductGroup which extends Page and I'm able to make ProductGroup pages in the CMS.My code:
$pg = new ProductGroup;
$pg->Title = "Test";
$pg->ParentID = 2;
$pg->write();This makes a valid entry in both Sitetree_Live and ProductGroup in the database and I can view that page in the website. It also makes an entry in Sitetree, but with the ClassName SiteTree, no Title and no ParentID (ParentID = 0). It kinda mucks things up in the CMS. The page is there, but in the root and not under node 2. It doesn't have an URLSegment so it's hard to click on and it's uneditable.
Is there any way I can have the Sitetree behave the same as Sitetree_Live?
TIA
-
Re: Adding page from controller

29 January 2010 at 12:17pm
With writing pages you need 2 lines. One to write, the other to sync the stage / live modes
$page->write();
$page->publish("Stage", "Live");It doesn't have an URLSegment so it's hard to click on and it's uneditable.
So then you probably need to set its URLSegment when you create the object.
-
Re: Adding page from controller

29 January 2010 at 1:24pm Last edited: 29 January 2010 1:25pm
Thanks for the reply. The URLSegment is generated automatically so I don't have to set it. It just wasn't working in the Stage table.
I had to reverse Stage and Live in the publish function, as it was going well for the Live bit, but not the Stage bit.
$pg->publish("Live", "Stage");
made it work!
Thanks again.
| 533 Views | ||
|
Page:
1
|
Go to Top |


