Following the ComplexTableField example in Chapter 5 of the SilverStripe book, I've added a news item section for my home page with the following code:
NewsItem.php
class NewsItem extends DataObject {
static $db = array(
'Headline' => 'Varchar',
'Text' => 'Text',
'StartDate' => 'Date',
'EndDate' => 'Date',
'Link' => 'Varchar'
);
function getCMSFields() {
$fields = new FieldSet(
new TextField('Headline', 'Headline'),
new TextareaField('Text', 'Blurb'),
new TextField('Link', 'Link'),
new DateField('StartDate', 'Start Date'),
new DateField('EndDate', 'End Date')
);
return $fields;
}
}
HomePage.php
class HomePage extends Page {
static $db = array(
);
static $has_many = array(
'HomePageNews' => 'NewsItem'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$newsTable = new ComplexTableField($this, 'HomePageNews', 'NewsItem', array('Headline'=>'Headline', 'StartDate'=>'StartDate', 'EndDate'=>'EndDate'));
$fields -> addFieldToTab('Root.Content.NewsItems', $newsTable);
return $fields;
}
}
class HomePage_Controller extends Page_Controller {
}
For the most part things work...I have a lovely new "News Items" tab in the CMS, when I select add I get a pop-up with all of the correct fields, and the news items are saved and deleted from the database as expected.
However, the show and edit buttons produce a "500 - Internal server error" and the SilverStripe log shows:
[27-May-2010 02:49:29] Warning at \sapphire\core\model\DataObject.php line 1328: array_flip() [<a href='function.array-flip'>function.array-flip</a>]: The argument should be an array (http://www.devtechsys.mirror/admin/EditForm/field/HomePageNews/item/1/show?ajax=1)
Thoughts?
Thanks so much.
Cheers,
Laurie