2013-01-14 73 views
-1

爲什麼選擇Zend \ Form \ Element \ Select中的空項目也被選爲零元素?Zend Framework 2:選擇元素 - 空選項

在窗體類:

$this->add(array(
'type' => 'Zend\Form\Element\Select', 
    'name' => 'active', 
    'options' => array(
     'label' => _('Active'), 
     'empty_option' => '', 
     'value_options' => array(
      1 => 'Yes', 
      0 => 'No', 
    ), 
), 
)); 

在控制器:

$searchForm->setData($request->getPost()); 

HTML,產生ZF2:

<select name="active"> 
    <option value="" selected="selected"></option> 
    <option value="1">Yes</option> 
    <option value="0" selected="selected">No</option> 
</select> 

回答

1

這幾乎與PHP如何解釋''做,0null in array() -context。我不確定這是否能夠解決當前的實現問題,但是我建議你在github上提出這個問題。

這個可能被認爲是一個錯誤。

+0

謝謝。我也認爲這是錯誤。我在github上就這個問題開了一個問題:https://github.com/zendframework/zf2/issues/3426 – Eremite