Hello, For example i have a 'country' and 'city' table in db. CountryID is referenced in city table.
How can i generate a dropdown list so that i have something like this:
Australia
- Sydney
- Melbourne
New Zealand
- Auckland
- Wellington
My code is something as below
City.php Model
function getActiveCities(){
$countries = Dataobject::get('Country', 'Active=1');
$allcities = new DataObjectSet();
foreach($countries as $country){
$cities = DataObject::get('DealCity', 'Active=1 AND CountryID='.$country->ID)->map('ID', 'Title');
$allcities->push($cities);
}
return $allcities;
}
Page Controller in CMS
...
$cities = City::getActiveCities();
$fields->addFieldToTab('Root.Content.Main', new DropdownField('City','Select city', $cities));
....
This does give the output of cities in the dropdown but not the expected output that i desire as above!
Can someone please eleborate on this or is there a better way of doing nested dropdowns in SS??
cheers
Nadz