I have created a page with a 1-many dataObject storing the names of a project and who is responsible. I need to create another 1-many table, so that inside the popup when adding a new record there is a drop down menu to select which person. I don't want to create a page for each person, like it does in the tutorial. Can onyone help?
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.
Hi,
Not sure to get you right
You mean adding a record in the projects table?
Take a look at this code.
class Person extends DataObject {
[...]
}
class Project extends DataObject {
static $has_one = array(
'Responsible' => 'Person'
);
function getCMSFields_forPopup() {
$fields = new FieldSet();
$mySet1 = DataObject::get('Person');
$map1 = $mySet1 ? $mySet1->toDropDownMap('ID', 'Name') : '';
$fields->push(new DropdownField('ResponsibleID',
'Grupo',
$map1
));
return $fields;
}
[...]
}
class ProjectHolder extends Page {
function getCMSFields() {
$fields = parent::getCMSFields();
$projectstable = new ComplexTableField(
$this,
'Projects ', //Relation Name that doesn't exists
'Project ',
array(
'ProjectName' => 'ProjectName',
'Responsible.Name' => 'Responsible'
),
'getCMSFields_forPopup'
);
$projectstable ->setParentClass(false);
$fields->push($projectstable);
}
Did it help?