Jump to:

3430 Posts in 1057 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » [SOLVED] Can't get GridField working in extended page

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

Page: 1
Go to End
Author Topic: 208 Views
  • Stephan
    Avatar
    Community Member
    55 Posts

    [SOLVED] Can't get GridField working in extended page Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: [SOLVED] Can't get GridField working in extended page Link to this post

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

  • Stephan
    Avatar
    Community Member
    55 Posts

    Re: [SOLVED] Can't get GridField working in extended page Link to this post

    Thanks very much.
    That solved my problem

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