Jump to:

5514 Posts in 1733 Topics by 1219 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Fatal error when trying to use GridField

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

Page: 1
Go to End
Author Topic: 892 Views
  • oscarw_89
    Avatar
    Community Member
    4 Posts

    Fatal error when trying to use GridField Link to this post

    Hi!

    I've been trying to get the GeidField to work for my project, but I always end up with an error..
    I'm new to Silverstripe so I probobly just made a mistake somewhere..

    Well, my problem is that I get this error message:

    Fatal error: Call to a member function getName() on a non-object in ...\framework\forms\FieldList.php on line 405

    I have a page extention where I want to have a grid field to add childs..

    - - PlayerPage.php - -

    <?php
    class PlayerPage extends Page {
       static $description = "Video player page";
       static $db = array(
          "VideoURL" => "Varchar",
          "SpeakerVideoURL" => "Varchar"
       );

       static $has_one = array(
          "Sidebar" => "WidgetArea",
          'VideoPhoto' => 'Image',
          'SpeakerVideoPhoto' => 'Image',
          'Video' => 'Video',
          'SpeakerVideo' => 'Video'
       );
       
       static $has_many = array(
          "Chapters" => "Chapter"
       );
       
       public function getCMSFields() {
          $fields = parent::getCMSFields();
          
          /* Video tab */
          $fields->addFieldToTab("Root.Video", new TextField('VideoURL', 'URL to main video'));
          $fields->addFieldToTab("Root.Video", new UploadField('Video', 'Main video'));
          $fields->addFieldToTab("Root.Video", new UploadField('VideoPhoto', 'Poster image for main video'));
          $fields->addFieldToTab("Root.Video", new TextField('SpeakerVideoURL', 'URL to speaker video'));
          $fields->addFieldToTab("Root.Video", new UploadField('SpeakerVideo', 'Speaker video'));
          $fields->addFieldToTab("Root.Video", new UploadField('SpeakerVideoPhoto', 'Poster image for speaker video'));
          
          /* Chapters tab */
          
          $itemsInGrid = $this->Chapters();
          //$itemsInGrid = DataList::create('Chapter');
                
          $gridColumns = new GridFieldDataColumns();
          
          $gridColumns->setDisplayFields(array(
             'Name' => 'Name',
             'Type' => 'Type',
             'StartTime' => 'Start time',
             'EndTime' => 'End time'      
          ));   
          
          $gridFieldConfig = GridFieldConfig::create()->addComponents(
          new GridFieldToolbarHeader(),
          new GridFieldAddNewButton('toolbar-header-right'),
          new GridFieldSortableHeader(),
          //new GridFieldDataColumns(),
          new GridFieldPaginator(10),
          new GridFieldEditButton(),
          new GridFieldDeleteAction(),
          new GridFieldDetailForm() ,
          $gridColumns
          );
          
          $gridField = new GridField("Chapters", "Chapters", $itemsInGrid, $gridFieldConfig);
          
          $fields->addFieldToTab("Root.Chapters", $GridField);
          
          /* Widgets tab */
          $fields->addFieldToTab("Root.Widgets", new WidgetAreaEditor("Sidebar"));

          return $fields;
       }
       
    }
    class PlayerPage_Controller extends Page_Controller {

    }

    - - Chapters.php - -

    <?php
    class Chapter extends DataObject {
       static $db = array(
          "Name" => "Varchar",
          "Type" => "Varchar",
          "StartTime" => "Decimal",
          "EndTime" => "Decimal"
       );

       static $has_one = array(
          "Player" => "PlayerPage"
       );
       
       static $summary_fields = array(
          'Name' => 'Name',
          'Type' => 'Type',
          'StartTime' => 'Start time',
          'EndTime' => 'End time'
       );
       
       public function getName() {
          return "Chapter";
       }
       
       public function getCMSFields() {
          $fields = parent::getCMSFields();
          return $fields;
       }
    }

    Sense the error says that it's calling a non-object I'm guessing that "$this->Chapters();" isn't geting the chapters..

    Thanks in advance for any help that could put me back on track again.

    //Oscar

  • jak
    Avatar
    Community Member
    46 Posts

    Re: Fatal error when trying to use GridField Link to this post

    The problem might be that you have a typo in your code: $GridField != $gridField
    It should be:

    $gridField = ...
    $fields->addFieldToTab("Root.Chapters", $gridField);

  • oscarw_89
    Avatar
    Community Member
    4 Posts

    Re: Fatal error when trying to use GridField Link to this post

    Haha

    That was the problem.

    And I spent hours looking for what was wrong..

    Thanks for the help!

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