2011-05-25 112 views
5

我有一個下拉Element_Select,我正在變成一個自定義元素Element_SelectCustom,以便我可以直接使用值填充它。這是自定義元素擴展Zend_form_element_select,錯誤消失

<?php 

require_once ('Zend/Form/Element/Select.php'); 

class Zend_Form_Element_SelectCustom extends Zend_Form_Element_Select 
{ 
    public function init() { 
     $this->addMultiOptions(array(
      'NULL' => 'Choose Value', 
      '1' => 'First', 
      '2' => 'Second', 
      '3' => 'Third', 
     )); 
     return parent::init(); 
    } 

的問題是,當我新的自定義元素添加到窗體並將其設置爲需要的,它不會,當我不選擇一個值觸發一個錯誤。

$test = new Zend_Form_Element_SelectCustom('test'); 
$test->setRequired(true); 
$this->addElement($test); 

我不知道它有什麼問題。有沒有其他方法可以重新啓動?

回答

3

您必須將'NULL'更改爲NULL。第一個是內容爲「NULL」的字符串,後者爲空值。一個空字符串''應該也很好。

public function init() 
{ 
    $this->addMultiOptions(array(
     NULL => 'Choose Value', // '' => 'Choose Value' 
     '1' => 'First', 
     '2' => 'Second', 
     '3' => 'Third', 
    )); 
    return parent::init(); 
} 
+0

謝謝你,看起來就是這樣。 – sameold 2011-05-26 07:05:37