我有一个地址DataObject
:
class Address extends DataObject{
private static $db = array(
'Address' => 'varchar(255)',
);
private static $many_many = array(
'Countries' => 'Country'
);
public function getCMSFields() {
$fields = FieldList::create(TabSet::create('Root'));
$fields->addFieldsToTab('Root.Main', array(
TextField::create('Name'),
ListBoxField::create('Countries', 'Countries')->setMultiple(true)->setSource(Country::get()->map('ID', 'Name'))
));
return $fields;
}
}
国家dataObject
:
class Country extends DataObject{
private static $belongs_many_many = array(
'Addresses' => 'Address',
);
private static $countries = array(
"AF" => array("Name"=>"Afghanistan","PhoneExtension"=>"+93"),...
);
public static function get($callerClass = null, $filter = "", $sort = "", $join = "", $limit = null, $containerClass = 'DataList') { $return = new ArrayList();
$i = 1; //if I do 0 it always populates the admin field.
foreach (self::$countries as $key => $value) {
$return->add(new ArrayData(array('ID' => $i, 'Acronym' => $key, 'Name' => $value['Name'])));
$i++;
}
return $return;
}
}
**更新**
在数据库中,这会正确保存,但它无法在CMS管理员中正确返回。我错过了什么?