Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Customising the CMS

ComplexTableField always has only ID-Column


Reply

2 Posts   1162 Views

Avatar
Nezzico

15 June 2009 at 5:47pm (Last edited: 15 June 2009 5:52pm), Community Member, 1 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

Avatar
Willr

16 June 2009 at 5:30pm Forum Moderator, 5511 Posts

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