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