5102 Posts in 1520 Topics by 1116 members
| Go to End | Next > | |
| Author | Topic: | 3426 Views |
-
Automatically Creating Child Pages

4 March 2009 at 10:41am
Hello,
Can a page type be configured to automatically create a child page when it is created?
Example: user creates a SpecialPage; a ChildSpecialPage automatically appears underneath the new SpecialPage.
Thank you,
Ben -
Re: Automatically Creating Child Pages

14 March 2009 at 7:19am Last edited: 14 March 2009 7:19am
This is possible! http://silverstripe.org/customising-the-cms/show/256077#post256077 clued me in.
In the page under which the child pages should automatically be created:
public function onAfterWrite() {
$cp = new ChildPage();
$cp->ParentID = $this->ID;
$cp->Title = "Test Page";
...
$cp->write();
return parent::onAfterWrite();
} -
Re: Automatically Creating Child Pages

18 March 2009 at 1:18am
hmmm could you show complete code ?
in ProgramHolder i paste yours but it doesn't work
class ProgramHolder extends SiteTree {
static $db = array(
);
static $has_one = array(
);
static $allowed_children = array('ProgramPage');
}class ProgramHolder_Controller extends ContentController {
public function onAfterWrite() {
$cp = new ProgramPage();
$cp->ParentID = $this->ID;
$cp->Title = "Test Page";$cp->write();
return parent::onAfterWrite();
}}
-
Re: Automatically Creating Child Pages

18 March 2009 at 1:58am
Hi Snaip,
Your code looks similar to mine, except for the location of onAfterWrite(). It needs to be in the ProgramHolder class, not the controller class. It's after ProgramHolder is written that the children should be created.
Ben
-
Re: Automatically Creating Child Pages

18 March 2009 at 2:07am Last edited: 18 March 2009 2:08am
nothing
sometimes i hate SS :[
-
Re: Automatically Creating Child Pages

18 March 2009 at 3:15am
you are using 2.3 right? There was no onAfterWrite() in previous stable versions.
-
Re: Automatically Creating Child Pages

18 March 2009 at 7:05am Last edited: 18 March 2009 7:12am
yeeeee it works in 2.3
thx xD
-
Re: Automatically Creating Child Pages

18 March 2009 at 9:49am Last edited: 20 March 2009 10:59pm
it works but ... it's creating me 4 copies of the same page ? !!
when i create ProgramHolder it adds me one ProgramPage, oknext log out, log in, and im geting another 3 copies of the new ProgramPage !!
why ? !
| 3426 Views | ||
| Go to Top | Next > |


