Dear All,
I've tried google around but i've found no solution to creating a dropdown list with a DataObject::get()
The background is that i'm trying to set up a store to show which district(area) is my product is located. This is what i've done.
<?php
class District extends DataObject {
static $db = array(
'Name' => 'Varchar(50)',
);
static $has_one = array(
'StateID' => 'State'
);
}
?>
also a State DataObject
<?php
class State extends DataObject {
static $db = array(
'Name' => 'Varchar(50)'
);
}
?>
Then i want it shows up as a pull down menu in my Product, so i did this in Product.php's getCMSFields()
function getCMSFields() {
$fields = parent::getCMSFields();
...
//Database request for the object
$myDataSet = DataObject::get("District");
# if($myDataSet){
// This returns an array of ID => Title
$map = $myDataSet->toDropDownMap();
$fields->addFieldToTab("Root.Content.Main", new ListboxField(
'District',
'District',
$map,
$map[0])
);
# }
...
return $fields;
}
But DataObject::get("District"); gives me null, it seems that Product.php cannot access the District object.
It seems my O-O concepts are really bad, can anyone give me a hand?
Thanks in advance!