我正在使用magento开发一个自定义模块,但我无法定义多选元素的选项
$this->_addFieldsToFieldset($fieldset, array(
'cities' => array(
'label' => $this->__('Cities'),
'input' => 'multiselect',
'required' => true,
'options' => $zoneSingleton->getAvailableCities(),
),
));
...和getAvailableCities()就像,
$read = Mage::getSingleton('core/resource')->getConnection('core_read');
$results = $read->fetchAll("SELECT * from districts");
$options = array();
foreach($results as $row)
{
$options[$row['city_id']] = $row['city'];
}
return $options;
}
但显示了多选元素,但未在表单中填充。但如果我将它设置为普通的选择元素,它就会被填充。我错过了什么?
答案 0 :(得分:1)
对于其他有同样问题的人
$ this-> _addFieldsToFieldset($ fieldset,array(
'cities' => array(
'label' => $this->__('Cities'),
'input' => 'multiselect',
'required' => true,
'values' => $zoneSingleton->getAvailableCities(),
),
));
上述选项中的应该是对值的更改,而值数组应该采用以下格式
$options[]= array('value'=>$row['city_id'], 'label'=>$row['city']);