我正在尝试填充选择列表(Zend_Form_Element_Select
),我尝试了这两个数组。 (这些是var转储)
这个有效:
array(2) {
[0] => array(2) {
["key"] => int(1)
["value"] => string(4) "Test"
}
[1] => array(2) {
["key"] => int(2)
["value"] => string(5) "Test2"
}
这个没有:
array(3) {
[0] => array(2) {
["key"] => int(1)
["value"] => string(16) "Test Kategorie 1"
}
[1] => array(2) {
["key"] => int(2)
["value"] => string(16) "Test Kategorie 2"
}
[2] => array(2) {
["key"] => int(3)
["value"] => string(4) "rene"
}
}
这是我的代码片段:
$select = new Zend_Form_Element_Select('video_category', array(
'required' => true,
'label' => 'label_video_category',
//'multioptions' => $this->categories,
'description' => 'text_video_category',
'class' => 'input',
'id' => 'select_video_category'
));
$options = array(
array( 'key' => 1,
'value' => 'Test'),
array( 'key' => 2,
'value' => 'Test2'),
);
Zend_Debug::dump($options);
$select->addMultioptions($this->categories);
$this->addElement($select);
所以,如果有人对我有任何线索,我会非常感激,因为我现在已经坚持了几个小时......
答案 0 :(得分:1)
您正在 addMultioptions 中使用 $ this->类别。只需验证您是否将选项分配给此变量。
$this->categories = $options;
以下代码对我来说都适用于这两个数组:
$form = new Zend_Form();
$select = new Zend_Form_Element_Select('video_category', array(
'required' => true,
'label' => 'label_video_category',
'description' => 'text_video_category',
'class' => 'input',
'id' => 'select_video_category'
));
$select->addMultioptions($this->categories);
$form->addElement($select);
使用的数组:
$options = array(
array( 'key' => 1,
'value' => 'Test'),
array( 'key' => 2,
'value' => 'Test2'),
);
$options = array(
array( 'key' => 1,
'value' => 'Test Kategorie 1'),
array( 'key' => 2,
'value' => 'Test Kategorie 2'),
array( 'key' => 3,
'value' => 'rene')
);