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.

General Questions /

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

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

Cannot instantiate abstract class Object - Error (Solved)


Reply


3 Posts   3790 Views

Avatar
prawnstar

Community Member, 127 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 [url=http://doc.silverstripe.org/tutorial:5-dataobject-relationship-management]here[/url].

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, 5513 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
prawnstar

Community Member, 127 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