Php 试图在ZF form 1.12中设置多个选项,相同的阵列结构,一个有效,另一个无效';为什么不工作?

Php 试图在ZF form 1.12中设置多个选项,相同的阵列结构,一个有效,另一个无效';为什么不工作?,php,zend-framework,zend-form,Php,Zend Framework,Zend Form,我试图填充一个选择列表(Zend\u Form\u Element\u select),我尝试了这两个数组。(这些是var转储) 这一个有效: array(2) { [0] => array(2) { ["key"] => int(1) ["value"] => string(4) "Test" } [1] => array(2) { ["key"] => int(2) ["value"] => string(5)

我试图填充一个选择列表(
Zend\u Form\u Element\u 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);
所以,如果有人能给我任何线索,我会非常感激,因为我已经被困在这里好几个小时了…

你正在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')
    );
您正在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')
    );

嘿,非常感谢你抽出时间。我发现错误,它不是在我的代码,而是在数据库和文件编码…嘿,非常感谢你的时间。我发现了错误,它不在我的代码中,而是在数据库和文件编码中。。。