Jump to:

5520 Posts in 1734 Topics by 1223 members

Customising the CMS

SilverStripe Forums » Customising the CMS » ComplexTableField always has only ID-Column

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

Page: 1
Go to End
Author Topic: 1132 Views
  • Nezzico
    Avatar
    Community Member
    1 Post

    ComplexTableField always has only ID-Column Link to this post

    Hello from Germany,

    in the moment i make my first experiences with Silverstripe, while rebuilding my own website before i use it for customers. in the moment i still have an problem with the complextabelfield, again and again. Here is a simple example, for testing issues, that wont work:

    First the Data:

    <?php

    class Frage extends DataObject {

    static $db = array(
    'Frage' => 'Text',
    'Antwort' => 'Text',
    );

    static $has_one = array(
    'Seite' => 'FAQ',
    );

    static $singular_name ="Frage";
    static $plural_name ="Fragen";

    function getCMSFields() {
    $fields = new FieldSet(
    new TextField('Frage','Frage'),
    new TextAreaField('Antwort','Antwort')
    );

    return $fields;
    }

    }

    ?>

    And now the Page:
    <?php

    class FAQ extends Page {

    public static $db = array(

    );

    public static $has_many = array(
    'Fragen' => 'Frage'
    );

    function getCMSFields() {
    $fields = parent::getCMSFields();

    $newTable = new ComplexTableField(
    $this,
    'Fragen',
    'Frage',
    null,
    null,
    "Frage.SeiteID = {$this->ID}"
    );
    $fields->addFieldToTab("Root.Content.Fragen",$newTable);

    return $fields;
    }

    }

    class FAQ_Controller extends Page_Controller {

    public function init() {
    parent::init();
    }

    }

    ?>
    This works, but my Table has only the Column ID. I tried to modify that by setting the third parameter of the complextablefield-Constructor with an array instead of null, but this causes an error, when adminarea should show the page for edit.

    Which stupid error do I made??? I have this problem again and again. Thanks you a lot for a helping hint!

    Heiner

  • Willr
    Avatar
    Forum Moderator
    5490 Posts

    Re: ComplexTableField always has only ID-Column Link to this post

    3rd parameter should be an array. You must have had a typo with it.

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