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.

Template Questions /

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

problem with RenderWith() function.


Go to End


3 Posts   2232 Views

Avatar
Benas

Community Member, 7 Posts

7 April 2012 at 2:37am

Hi,

what is wrong with my code? I`m getting error: "Fatal error: Call to a member function renderWith() on a non-object in"

This is my code:

DropDownMenu.php:

 <?php

class DropDownMenu extends DataObjectDecorator {
	
	function extraStatics() {
		return array(
			'db' => array (
				'DropDownMenu' => 'Boolean',
			),
			'has_one' => array(
				
            )
		);
	}
	
	public function updateCMSFields(FieldSet &$fields) {
         
       $fields->addFieldToTab("Root.Content.Main", new CheckBoxField("DropDownMenu","Drop down menu"), "Content");
		
    }	
	public function dropdownmennu(){
		return $this->parent->renderWith('dropdownmenu');
	}
}
class DropDownMenu_Controller extends ContentController {
	function init(){
	
		parent::init();
		Requirements::css("dropdownmenu/css/dropdownmenu.css");	
	}
}

Avatar
dizzystuff

Community Member, 94 Posts

8 April 2012 at 2:51am

Hi Benas

I'm pretty sure

$this->parent->renderWith('dropdownmenu');

should read

$this->owner->renderWith('dropdownmenu');

Avatar
Benas

Community Member, 7 Posts

8 April 2012 at 6:20am

Edited: 08/04/2012 6:21am

It works! Thank you! :)