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.

Data Model Questions /

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

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


Go to End


3 Posts   2223 Views

Avatar
linkoovi

Community Member, 12 Posts

17 August 2013 at 7:49am

Edited: 17/08/2013 7:51am

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?

Avatar
martimiz

Forum Moderator, 1391 Posts

19 August 2013 at 5:36am

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 :)

Avatar
linkoovi

Community Member, 12 Posts

19 August 2013 at 6:20am

Edited: 19/08/2013 6:20am

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

I need to get out more!

Thanks mate!!

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