2010-05-20 34 views

回答

1

在ZF編程形式僅支持參數類型,名稱和選項(未在選擇的含義,但的元件設置等所需或標籤)的形式的元素。假設多個值會動態地進行設定,如:

$formConfig = new Zend_Config_Xml('/path/to/form.xml'); 
$form = new Zend_Form($formConfig); 
$form->getElement('myselect')->setMultiOptions($arrayOfOptions); 

當然還有的用自己的名字約定在實際設置XML文件中的元素選項(將由Zend_Form中被忽略)的可能性,然後負載他們從那裏,而不必硬編碼或在運行時檢索到的,例如:

<?xml version="1.0" encoding="UTF-8"?> 
<form> 
    <user> 
     <example> 
      <name>mysampleform</name> 
     <method>post</method> 
     <elements> 
     <myselect> 
       <type>select</type> 
       <name>myselect</name> 
       <multioptions> <!-- custom tag --> 
        <option value="First">1</option> 
        <option value="Second">2</option> 
        <option value="Third">3</option> 
       </multioptions> 
       <options> 
        <label>Choose an option:</label>       
        <required>true</required> 
       </options> 
      </myselect> 
      <submit> 
      <type>submit</type> 
      <options> 
       <value>Submit</value> 
      </options> 
      </submit> 
     </elements>  
    </example> 
</user> 

$formConfig = new Zend_Config_Xml('/path/to/form.xml'); 
$form = new Zend_Form($formConfig); 
$form->getElement('myselect')->setMultiOptions(
    $formConfig->user->example->elements->myselect->multioptions->toArray() 
); 

然而,這似乎並沒有更effecti而不僅僅是將這些選項存儲在其他地方。

+0

謝謝你簡潔的回答。我將使用一個數組! – ben 2010-05-21 09:17:29

相關問題