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