Jump to:

3433 Posts in 1058 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Silverstripe 3 GridField $this->METHODNAME() does not exist

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

Page: 1
Go to End
Author Topic: 392 Views
  • linkoovi
    Avatar
    Community Member
    12 Posts

    Silverstripe 3 GridField $this->METHODNAME() does not exist Link to this post

    Hi,
    I am getting an error when trying to create a GridField.

    GET http://localhost/sspass/admin/pages/edit/show/36
       
    500 Error at line 675 of /home/USERNAME/www/sspass/framework/core/Object.php

    ERROR [User Error]: Uncaught Exception: Object->__call(): the method 'sspassgroups' does not exist on 'SspassPage'
    IN GET /sspass/admin/pages/edit/show/36
    Line 675 in /home/USERNAME/www/sspass/framework/core/Object.php

    I have 2 DataObject

    SspassAccount.php
    ----------------------------------------------

    class SspassAccount extends DataObject{

    public static $db = array(
    'Name' => 'Varchar(255)',
    'Content' => 'HTMLText'
    );
    public static $has_one = array(
    'SspassPage' => 'SspassPage',
    'SspassGroup' => 'SspassGroup'
    );

    public static $singular_name = 'SspassAccount';
    public static $plural_name = 'SspassAccounts';

    public function getCMSFields() {
    parent::getCMSFields();

    $fields = new FieldList(
    new TextField( 'Name' , 'Account Name') ,
    new TextareaField( 'Content' , 'Content')
    );
    return $fields;
    }
    }

    SspassGroup.php
    ----------------------------------------------

    class SspassGroup extends DataObject{

    public static $db = array(
    'Name' => 'Varchar(255)'
    );

    public static $has_meny = array(
    'SspassAccounts' => 'SspassAccount'
    );

    public static $has_one = array(
    'SspassPage' => 'SspassPage'
    );

    static $singular_name = 'SspassGroup';
    static $plural_name = 'SspassGroups';

    public function getCMSFields() {
    parent::getCMSFields();

    $fields = new FieldList(
    new TextField( 'Name' , 'Name')
    );
    return $fields;
    }
    }

    and the page

    SspassPage.php
    ----------------------------------------------

    class SspassPage extends Page{

       public static $db = array(

       );

       public static $has_one = array(
       );

    public static $has_meny = array(
    'SspassAccounts' => 'SspassAccount',
    'SspassGroups' => 'SspassGroup'

    );
    public function getCMSFields(){
    $fields = parent::getCMSFields();

    $config = GridFieldConfig_RelationEditor::create();
    $config->getComponentByType('GridFieldDataColumns')->setDisplayFields(array(
    'Name' => 'Name'
    ));
    // Create a gridfield to hold the student relationship
    $groupsField = new GridField(
    'SspassGroups',
    'SspassGroups',
    $this->SspassGroups(), // <--------- ERROR [User Error]: Uncaught Exception: Object->__call(): the method 'sspassgroups' does not exist on 'SspassPage'
    $config
    );

    $fields->addFieldToTab( 'Root.Groups', $groupsField);

    return $fields;
       }
    }


    The bussiness logic:
    SspassPage should have 2 tabs, one for adding accounts and one for edding groups, one groupe has meny accounts

    Am I missing something?

  • martimiz
    Avatar
    Forum Moderator
    1068 Posts

    Re: Silverstripe 3 GridField $this->METHODNAME() does not exist Link to this post

    Small typo: $has_meny should be $has_many in classes SspassGroup and SspassPage.

    Btw hope we're not supposed to take your eh... 'greeting' seriously

  • linkoovi
    Avatar
    Community Member
    12 Posts

    Re: Silverstripe 3 GridField $this->METHODNAME() does not exist Link to this post

    Well I feel embarrassed now!! Thanks a lot, I would not see that for a long time .

    I need to get out more!

    Thanks mate!!

    PS. Dont take anything on the Internet seriously, life is too short!

    392 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.