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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

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

Cannot instantiate abstract class Object - Error (Solved)


Go to End


3 Posts   4747 Views

Avatar
digibrains

Community Member, 130 Posts

20 July 2010 at 12:52pm

Edited: 20/07/2010 1:43pm

Hi All,

I'm trying to set up a page (much like a blog page) in which subsections appear on the page. And within those subsections, I'm trying to create sub-sub-sections using the ManyManyComplexTableField(). But I'm getting a "Cannot instantiate abstract class Object" error when I try to view the CMS. I'm using the many_many tutorial found here.

Example:

(ResourceHolder)
|
> (ResourceSection)
>> (ResourceModule)
>> (ResourceModule)
|
> (ResourceSection)
>> (ResourceModule)
>> (ResourceModule)

/mysite/code/ResourceHolder.php
<?php
class ResourceHolder extends Page {
	static $allowed_children = array('ResourceSection');
	static $db = array();
	static $has_one = array();
	// return cms fields
}

class ResourceHolder_Controller extends Page_Controller {
}
?>
 

/mysite/code/ResourceSection.php
<?php
class ResourceSection extends Page {
	static $db = array();
	static $has_one = array();

	function getCMSFields() {
		$fields = parent::getCMSFields();
		$modulesTablefield = new ManyManyComplexTableField(
			$this,
			'ResourceSections',
			'ResourceSection',
			array(
				'Title' => 'Title'
			),
			'getCMSFields_forPopup'
		);
		$modulesTablefield->setAddTitle( 'A Module' );
		$fields->addFieldToTab( 'Root.Content.ResourceSections', $modulesTablefield );
		return $fields;
	}
}
?>

/mysite/code/ResourceModule.php
<?php
class ResourceModule extends DataObject {
	static $db = array(
		'Title' => 'Text',
		'Copy' => 'Text',
		'Link' => 'Text',
		'LinkText' => 'Text'
	);
	static $belongs_many_many = array(
		'ResourceSections' => 'ResourceSection'
	);
	function getCMSFields_forPopup() {
		$fields = new FieldSet();
		$fields->push(new TextField('Title'));
		$fields->push(new TextField('Copy'));
		$fields->push(new TextField('Link'));
		$fields->push(new TextField('LinkText'));
		return $fields;
	}
}
?>

Any help is greatly appreciated. Thanks!
Chris.b

Avatar
Willr

Forum Moderator, 5523 Posts

20 July 2010 at 1:08pm

One thing (I'm not sure if this is the actual cause of the error) but you appear to be missing the static $many_many = array('ResourceModules' => 'ResourceModule'); in ResourceSection.php (which is the other side to the belongs many many). Also the constructor for the manymany table should name the ResourceModule I believe rather than ResourceSection.

$modulesTablefield = new ManyManyComplexTableField(
$this,
'ResourceModules',
'ResourceModule',
array(
'Title' => 'Title'
),
'getCMSFields_forPopup'
);

Avatar
digibrains

Community Member, 130 Posts

20 July 2010 at 1:26pm

Will,

Somewhere in San Francisco, in about 15 minutes, there will be a pint raised in your honor.

Thank you!

Chris.b