Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions /

Setting a Default ParentID


Reply


3 Posts   529 Views

Avatar
zenmonkey

Community Member, 532 Posts

25 November 2012 at 1:25pm

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 ?

Avatar
Willr

Forum Moderator, 5513 Posts

2 December 2012 at 5:42pm

Use onBeforeWrite().

Avatar
zenmonkey

Community Member, 532 Posts

11 December 2012 at 3:52am

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.