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


2 Posts   1159 Views


28 January 2011 at 11:33am Community Member, 144 Posts

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')",


28 January 2011 at 12:33pm Community Member, 144 Posts

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 %>
<% control Vehicles %>
<a href="$link">$Model</a>
<% end_control %>
<% end_control %>