1

我正在尝试填充一个选择列表(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);

因此,如果有人对我有任何线索,我将非常感激,因为我已经坚持了几个小时......

4

1 回答 1

1

您在addMultioptions中使用$this->categories。只需验证您是否将选项分配给此变量。

     $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')
    );
于 2012-10-31T18:42:03.230 回答