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.

Data Model Questions

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


Reply

3 Posts   424 Views

Avatar
linkoovi

17 August 2013 at 7:49am (Last edited: 17 August 2013 7:51am), Community Member, 12 Posts

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

19 August 2013 at 5:36am Forum Moderator, 1091 Posts

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

19 August 2013 at 6:20am (Last edited: 19 August 2013 6:20am), Community Member, 12 Posts

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!