Select ZF2元素“;选择";及;“多检查盒”;渲染不正确

Select ZF2元素“;选择";及;“多检查盒”;渲染不正确,select,zend-framework2,element,Select,Zend Framework2,Element,为什么元素“select”和“multicheckbox”不能正确呈现(在html中)? 元素“文本”和“复选框”渲染正确 例如: 1) 格式代码: class Profile extends Form { public function __construct($name = null) { parent::__construct('page'); $this->setAttribute('action', 'info'); $

为什么元素“select”和“multicheckbox”不能正确呈现(在html中)? 元素“文本”和“复选框”渲染正确

例如:

1) 格式代码:

class Profile extends Form {

    public function __construct($name = null) {

        parent::__construct('page');
        $this->setAttribute('action', 'info');
        $this->setAttribute('method', 'post');        
        $this->setInputFilter($this->getFilters());`

        $this->add(array(     
            'type' => 'Zend\Form\Element\Select',       
            'name' => 'usernames',
            'attributes' =>  array(
               'id' => 'usernames'              
            ),
            'options' => array(
                'label' => 'User Name',
                'options' => array(
                    'test' => 'Hi, Im a test!',
                    'Foo' => 'Bar',
                ),
            ),
        ));

        $this->add(array(
             'type' => 'select',
             'name' => 'language',
             'options' => array(
                     'label' => 'Which is your mother tongue?',
                     'value' => array(
                             '0' => 'French',
                             '1' => 'English',
                             '2' => 'Japanese',
                             '3' => 'Chinese',
                     ),
             )
        ));
    }
2) 视图中的代码:

<h1><?php echo $this->translate('Profile') ?></h1>
<?php $form = $this->form; $form->prepare();?>
<?php echo $this->form()->openTag($form) ?>
    <dl class="zend_form">
    <?php foreach ($form as $element): ?>
        <?php if ($element->getLabel() != null): ?>
            <dt><?php echo $this->translate($this->formLabel($element)); ?></dt>
        <?php endif ?>
        <?php if ($element instanceof Zend\Form\Element\Button): ?>
            <dd><?php echo $this->formButton($element) ?></dd>
        <?php elseif ($element instanceof Zend\Form\Element\Captcha): ?>
            <dd><?php echo $this->formCaptcha($element) . $this->translate($this->formElementErrors($element)); ?></dd>
        <?php else: ?>
            <dd><?php echo $this->formInput($element) . $this->translate($this->formElementErrors($element)); ?></dd>
        <?php endif ?>
    <?php endforeach ?>
    </dl>
    <?php if ($this->redirect): ?>
        <input type="hidden" name="redirect" value="<?php echo $this->redirect ?>" />
    <?php endif ?>
    <input type="submit" value="<?php echo $this->translate('Submit'); ?>" />
<?php echo $this->form()->closeTag() ?>

formInput()
帮助程序专门用于输出
元素,因此ZF完全按照您的指示执行。你可能想要更像这样的东西:

<?php foreach ($form as $element): ?>
    <?php if ($element->getLabel() != null): ?>
        <dt><?php echo $this->translate($this->formLabel($element)); ?></dt>
    <?php endif ?>
    <dd><?php echo $this->formElement($element) . $this->translate($this->formElementErrors($element)) ?></dd>
<?php endforeach ?>

formElement()
助手将调用任何合适的助手

<select>
  <option>value 1</option>
  <option>value 2</option>
</select>
<?php foreach ($form as $element): ?>
    <?php if ($element->getLabel() != null): ?>
        <dt><?php echo $this->translate($this->formLabel($element)); ?></dt>
    <?php endif ?>
    <dd><?php echo $this->formElement($element) . $this->translate($this->formElementErrors($element)) ?></dd>
<?php endforeach ?>