Jump to:

23489 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Cannot instantiate abstract class Object - Error (Solved)

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

Page: 1
Go to End
Author Topic: 3621 Views
  • prawnstar
    Avatar
    Community Member
    116 Posts

    Cannot instantiate abstract class Object - Error (Solved) Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: Cannot instantiate abstract class Object - Error (Solved) Link to this post

    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'
    );

  • prawnstar
    Avatar
    Community Member
    116 Posts

    Re: Cannot instantiate abstract class Object - Error (Solved) Link to this post

    Will,

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

    Thank you!

    Chris.b

    3621 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.