Jump to:

3433 Posts in 1058 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Setting a Default ParentID

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 453 Views
  • zenmonkey
    Avatar
    Community Member
    527 Posts

    Setting a Default ParentID Link to this post

    I was wondering if its possible to set the ParentID of a pagetype to specific page. The pagetype is being controlled by a ModelAdmin instead of the pages interface. I've tryed setting the $defaults array in the __construct() but I get a class does not exist error

    static $defaults;   

       /**
        * Static methods
        * ----------------------------------*/
       
       public function __construct() {
          
       
          $mainListingPage = SiteTree::get_by_link("listings");
          
          
          $this->defaults = array(
             "ParentID" => $mainListingPage->ID,
          );
          
          parent::__construct();
       }

    Should I just handle it in the onBeforeWrite ?

  • Willr
    Avatar
    Forum Moderator
    5490 Posts

    Re: Setting a Default ParentID Link to this post

    Use onBeforeWrite().

  • zenmonkey
    Avatar
    Community Member
    527 Posts

    Re: Setting a Default ParentID Link to this post

    Calling it in onBefore write was failing I ended up adding a hidden ParentID field to the form and setting the value with the function. When I have a chance I'll try onBeforeWrite again so I can trackdown the actual issue.

    453 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.