Hmmm... something seems to be wrong...
I'm using SS2.3.0 and added Persons.php and FormContact.php to mysite/code.
In Persons.php I added
class Persons_Controller extends Page_Controller {
function onAfterWrite() {
if(!$this->Children()) {
$cp = new FormContact();
$cp->ParentID = $this->ID;
$cp->Title = "Contactform";
$cp->write();
}
return parent::onAfterWrite();
}
}
Next I did run a db/build just to be sure.
After that I logged in to the CMS and choose Persons in the pagetype-dropdown and clicked Go.
However, only a persons-page is created, without any contactform-subpage.
I also tried it without if(!$this->Children()){}, but with no luck either.
Am I making a mistake or am I expecting the wrong behaviour of onAfterWrite() and should I do something else to accomplish this?