w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Automatically create child page on Silverstripe page type

For this, I would create the TeamReport in an onAfterWrite method on TeamPage, after checking for creation in onBeforeWrite.

public function onBeforeWrite() {
    parent::onBeforeWrite();
    $this->IsCreating = !$this->ID;
}

public function onAfterWrite() {
    parent::onAfterWrite();
    if ($this->IsCreating) {
        $child = new TeamReport();
        $child->ParentID = $this->ID;
        $child->URLSegment = 'report';
        $child->Title = 'Report';
        $child->write();
    }
}




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.