Hello,
after update to SS 3 I needed to change from ComplexTableField to GridField
here my code
class Staff extends DataObject {
public static $db = array(
'Name' => 'Varchar',
);
public static $has_one = array(
'Parent'=>'StaffPage',
);
public static $summary_fields = array(
'Name' => 'Name'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->removeByName(ParentID');
return $fields;
}
}
class StaffPage extends Page {
public static $db = array();
static $has_one = array();
public static $has_many = array(
"Staff"=>"Staff"
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$config = GridFieldConfig_RecordEditor::create();
$staffField = new GridField(
'Staff',
'Staff',
$this->Staff(),
$config
);
$fields->addFieldToTab('Root.Staff', $kuechenField);
return $fields;
}
public function Staff() {
return Staff::get()->filter("ParentID", $this->ID)->sort("Name");
}
}
class StaffPage_Controller extends Page_Controller {}
everything works fine (edit, delete, view)
But I have a problem with adding new staff
I see the formular, put the data in the formular, do save
CMS shows the first page in in the site tree (after editing existing staff, it stays on staffpage) seems to be a problem
Looking in the datatabase I see the new staff but without StaffPage relation. ParentID is 0
Probebly the first problem depends on this missing relation I dont know
So I have first to fix the ParentID problem.
Any ideas how can I do this?
In the old version I had
public function getCMSFields() {
$fields = parent::getCMSFields();
$table = new ComplexTableField(
$this,
"Staff",
"Staff",
array("Name"=>"Name"),
null,
"Staff.ParentID = {$this->ID}"
);
$fields->addFieldToTab("Root.Content.Staff", $table);
return $fields;
}
so i missing "Staff.ParentID = {$this->ID}" with GridField
Thanks a lot in andvance