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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Fatal error in ModelAdmin


Go to End


4 Posts   1566 Views

Avatar
sonet

Community Member, 33 Posts

12 July 2010 at 4:15am

I am getting the follwing error in ModelAdmin 2.4:

Fatal error: Call to a member function getModelSidebar() on a non-object in cms/code/ModelAdmin.php on line 251:

'Content' => $this->$class->getModelSidebar()

	protected function getModelForms() {
		$models = $this->getManagedModels();
		$forms  = new DataObjectSet();
		
		foreach($models as $class => $options) { 
			if(is_numeric($class)) $class = $options;
			$forms->push(new ArrayData(array (
				'Title'     => (is_array($options) && isset($options['title'])) ? $options['title'] : singleton($class)->i18n_singular_name(),
				'ClassName' => $class,
				'Content'   => $this->$class->getModelSidebar()
			)));
		}
		
		return $forms;
	}

I do not understand this. Does anybody know, why this happens and what I can do to make it work?

Avatar
swaiba

Forum Moderator, 1899 Posts

12 July 2010 at 5:27am

Hi,

It is tough to solve without the code that is causing the error - believe me ModelAdmin is stable. My first guess would be that you have misspelled one of the static $managed_models = array('nonexistentdataobject','mispelleddataobject'); - if you cannot see any errors there (and you are sure all your data bojects are loading e.g. the FileName.php matches the class FileName extends DataObject()) then post the code of the model admin and data objects managed and maybe I can be more help.

Barry

Avatar
sonet

Community Member, 33 Posts

12 July 2010 at 9:29am

OMG! My code was ok... The problem was that I've used in one of my classes a reserved word. Renaming it solved it. Thanks for your help.

Avatar
swaiba

Forum Moderator, 1899 Posts

1 September 2010 at 12:28am

I just had a similar issue, found this thread so I thourght I'd add mine to it... I had a mangaed_model called 'XYZ' and then I defined a function within the ModelAdmin called 'XYZ'. Renaming the function sorted it all out...