2013-06-05 38 views
5

您好我是zend框架中的新成員。 我想在zend窗體中的輸入框上設置只有屬性。 例如我們在HTML如何在zend窗體中設置只讀屬性添加元素

<input type ="text" readonly="readonly" /> 

做,這是我的zend代碼:

$this->addElement('text', 'name', array(
      'label'  => '', 
      'required' => true, 
      'filters' => array('StringTrim'), 
      'style' => array('width:338px'), 
      'autocomplete' => 'off', 
      'decorators'=>Array(
      'ViewHelper', 
      'Errors', 

      ), 

幫助MEE

回答

5

嘗試是這樣的:

$this->addElement('text','text_field',array('attribs' => array('readonly' => 'true'))); 
+1

做同樣的事情爲收音機工作,在我的代碼中,它似乎沒有 – almaruf

7

試試這個

$this->getElement('text')->setAttrib('readonly', 'readonly'); 
3

在ZF2中,您可以通過擴展Zend \ Form來創建表單,然後在構造函數中添加表單元素。在那裏你可以設置如下的屬性。

use Zend\Form\Form; 

class MyForm extends Form { 
    public function __construct() { 

     $this->add(array(
      'name' => 'name', 
      'type' => 'Text', 
      'attributes' => array(
       'id' => 'name', 
       'class' => 'form-control', 
       'readonly' => TRUE, 
      ), 
      'options' => array(
       'label' => 'Name : ' 
      ) 
     )); 
    } 
} 
相關問題