Jump to:

5542 Posts in 1739 Topics by 1225 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Show and Edit producing errors with editor pop-up (2.4.0)

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

Page: 1
Go to End
Author Topic: 1443 Views
  • Laurie
    Community Member
    21 Posts

    Show and Edit producing errors with editor pop-up (2.4.0) Link to this post

    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:


    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;


    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)


    Thanks so much.


  • karoldvl
    Community Member
    1 Post

    Re: Show and Edit producing errors with editor pop-up (2.4.0) Link to this post

    I've stumbled here trying to debug the same error.

    Maybe it will be helpful for somebody in the future. I think you're missing the second part of the relation - at least that was my case.

    Adding in NewsItem.php:

    static $has_one = array(
    "HomePage" => "HomePage"

    should do the trick.

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.