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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

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

ComplexTableField always has only ID-Column


Go to End


2 Posts   1821 Views

Avatar
Nezzico

Community Member, 1 Post

15 June 2009 at 5:47pm

Edited: 15/06/2009 5:52pm

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

Forum Moderator, 5523 Posts

16 June 2009 at 5:30pm

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