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 /

[SOLVED] Can't get GridField working in extended page


Go to End
Reply


3 Posts   399 Views

Avatar
Stephan

Community Member, 55 Posts

19 January 2014 at 12:22pm

Edited: 19/01/2014 12:25pm

Hi experts,
I'm extending a product page via DataExtension

class ProductPropertiesExtension extends DataExtension {
…..
private static $has_many = array(
        'Accessories' => 'ProductAccessory'
    );
…...

with Accessory.php

class ProductAccessory extends DataObject {
    private static $db = array(
        'ProductID' => 'Int'
    );
    private static $has_one = array(
        'Product' => 'Product'
    );  
}

The table ProductAccessory is created.

Then I try to add a grid field in my extension class with:
(the GridField is not yet configured correctly, it's just a test)

public function updateCMSFields(FieldList $fields) {
		// Create a default configuration for the new GridField, allowing record editing
        $config = GridFieldConfig_RelationEditor::create();
        // Set the names and data for our gridfield columns
        $config->getComponentByType('GridFieldDataColumns')->setDisplayFields(array(
            'Title' => 'Title'
        ));
		
        // Create a gridfield to hold the accessory relationship    
        $accessoriesField = new GridField(
            'Accessories', // Field name
            'Product', // Field title
            $this->Accessories(), // List of all related accessories
            $config
        );      
        // Create a tab named "Accessories" and add our field to it
        $fields->addFieldToTab('Root.Accessories', $accessoriesField); 
}

But then I get the error:
Call to undefined method ProductPropertiesExtension::Accessories() in /Applications/XAMPP/xamppfiles/htdocs/swipestripe-funds/code/Product.php on line 352

What am I doing wrong?

TIA Stephan

Avatar
Willr

Forum Moderator, 5514 Posts

19 January 2014 at 10:16pm

Edited: 19/01/2014 10:16pm

Try $this->owner->Accessories() rather than $this->Accessories()

Avatar
Stephan

Community Member, 55 Posts

20 January 2014 at 1:25am

Thanks very much.
That solved my problem :-)