1779 Posts in 582 Topics by 556 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1385 Views |
-
Mapping Two Fields using toDropDownMap ??

26 January 2010 at 2:43am
Hi,
I'm trying to figure out how to show two fields side by side in a single, mapped dropdown. For example in the code below I want the dropdown to display the combination of FirstName + LastName (and Map it to that Author's ID). I can work with a single field (either FirstName OR LastName) but can't seem to concatenate them both to be displayed in the Dropdown...
//This works fine but I need to include the LastName also
$authorData = DataObject::get('Author');
if($authorData->exists()) {
$AuthorSource = $authorData->toDropDownMap('ID', 'FirstName', 'Select Author');
}I tried using a function eg.
$authorData->toDropDownMap('ID', 'getFullName', 'Select Author');
and the function
function getFullName(){
$authorData = DataObject::get('Author');
return $authorData->FirstName.", ".$authorData->LastName;}
But I had no luck with this. Would appreciate any help on this. It's driving me mad.
Regards,
Ciarán -
Re: Mapping Two Fields using toDropDownMap ??

29 January 2010 at 7:34am
Well an you could also create an extra column on your DataObject that contains the full name and fill it with an onBeforeWrite instead of manually filling it in. Thats a quick in-elegant fix. My only other idea is even more complex. You could output the first name and last name to arrays and marry them back up, but I don't know if you can Map and array to drop down
-
Re: Mapping Two Fields using toDropDownMap ??

8 March 2012 at 4:35pm
I know this is very late but I recently just ran into the same issue. So my solution may help for those that find this page.
You can reference a function, as you know, in your toDropDownMap call instead of a field.
$member = $member->toDropdownMap('ID', 'getName', '(Select one)', true);
Either create a function in your custom class. Or use these ones that already exist in the Member class:
getTitle will return 'Surname, FirstName'
getName will return 'FirstName Surname'
| 1385 Views | ||
|
Page:
1
|
Go to Top |



