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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

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

Setting a Default ParentID


Go to End


3 Posts   1373 Views

Avatar
zenmonkey

Community Member, 545 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, 5523 Posts

2 December 2012 at 5:42pm

Use onBeforeWrite().

Avatar
zenmonkey

Community Member, 545 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.