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 /

[SOLVED] Convert Enum to Dataobject


Reply


2 Posts   1260 Views

Avatar
NickJacobs

Community Member, 144 Posts

28 January 2011 at 11:33am

Hi... I need to convert db enum values to a dataobject so I can loop through them in a template...can anyone help with this??
Enum looks like:

'Make' => "Enum('Ford,Great Wall,Holden,Isuzu,Mazda,Mitsubishi,Nissan,Toyota,VW')",

Avatar
NickJacobs

Community Member, 144 Posts

28 January 2011 at 12:33pm

ok....found it with a bit more searching and mucking around :)

public function BuildVehicleMenu() {
$doSet = new DataObjectSet();
foreach(singleton('VehicleItem')->dbObject('Make')->enumValues() as $make) {
$doSet->push(new ArrayData(array(
'MakeName' => $make,
'Vehicles' => DataObject::get("VehicleItem","Make = '$make'")
)));
}

return $doSet;
}

template example:

<% control BuildVehicleMenu %>
$MakeName
<% control Vehicles %>
<a href="$link">$Model</a>
<% end_control %>
<% end_control %>