MillyMonster MillyMonster - 4 months ago 21x
PHP Question

Displaying DataObject name in summary fields of DataObjectManager

Firstly I'm using version 2.4.7 of SilverStripe. I have a has_one relationship between a DataObject I am using, with DataObjectManager, and another DataObject. I want to display the name of the DataObject in the summary fields of the DataObjectManager but I keep getting the error below.

Uncaught Exception: Object->__call(): the method 'fortemplate' does not exist on 'Store'

I assume it is because I have it in a has_one relationship but I'm not sure. Does anyone have any suggestions about how I can do this?



You are getting that error because "Store", when in the summary fields returns the Store object. Summary fields doesn't quite know what to do with the object, so it checks to see if it has a "forTemplate" method, which would normally return the object rendered with a template or just a plain string.

Here's two options:

1) create the forTemplate() method on you Store object, which returns the Title (or whatever field you want) of the Store.


2) On your object that has the DataObjectManager field on it, create a getter method that returns the Title of the Store. ie..

public function getStoreTitle(){
    return $this->Store()->Title

And then refer to that method in summary_fields ie...

public static $summary_fields = array(