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.

Data Model Questions /

merge DataObject::get


Reply


2 Posts   2717 Views

Avatar
snaip

Community Member, 180 Posts

2 April 2009 at 1:42am

i want to merge two DataObject::get and result puts into DropDownField

first i tryed

$en = DataObject::get("ENTourPage")->toDropdownMap('Title', 'Title');
$home = DataObject::get("PLHomePage")->toDropdownMap('Title', 'Title');
$en -> merge($home);

[...]

$fields->addFieldToTab("Root.Content.Tlumaczenie", new DropdownField('EN','Angielskie:',$wynik));

but i get
Fatal error: Call to a member function exists() on a non-object in ... on line ...

second i tryed like in here http://www.silverstripe.org/data-model-questions/show/257050#post257050

$result = new DataObjectSet();
$result -> merge (DataObject::get("ENTourPage")->toDropdownMap('Title', 'Title'));
$result -> merge (DataObject::get("PLHomePage")->toDropdownMap('Title', 'Title'));

[...]
$fields->addFieldToTab("Root.Content.Tlumaczenie", new DropdownField('EN','Angielskie:',$result));


but now i get only empty field in DropDownField

Avatar
Bambii7

Community Member, 254 Posts

17 September 2009 at 7:33pm

I had the same problem with a system I'm trying to put together.
But I just realized you're merging two different dataobjets, that could be a bit of an issue.
My solution was
$studentData = DataObject::get('Student');
$StudentMap = $studentData->toDropDownMap('ID', 'ChildFirstName');
foreach($studentData as $Student) {
   $StudentMap[$Student->ID] = $StudentMap[$Student->ID].' '.$Student->ChildLastName;
}
$students = new MultiSelectField(
   "Students", // Relationship
   "Students", // Field name
   $StudentMap // Source records (array)
);

But you could try something like

$enMap = DataObject::get('ENTourPage')->toDropDownMap('ID', 'Title');//NOTE you'll want to make use of the ID not Title Title
$home = DataObject::get("PLHomePage");
foreach($home as $PLHomePage) {
$enMap[$PLHomePage->ID] = $PLHomePage->Title;
}
$fields->addFieldToTab("Root.Content.Tlumaczenie", new DropdownField('EN','Angielskie:',$enMap));

There might be an easier way but I'm not sure.