2014-02-27 129 views
0

我是ZF2的新手,我正在重寫一個先前用ZF1寫過的簡單應用程序。我有一個表格,我想要自定義,因爲默認輸入/ textearea寬度和heigth不夠。在這裏我對我的形式的某些字段代碼:設置表單元素屬性

$this->add(array(
    'name' => 'page', 
    'type' => 'Number', 
    'options' => array(
     'label' => 'Page', 
    ), 
)); 
$this->add(array(
    'name' => 'name', 
    'type' => 'Text', 
    'options' => array(
     'label' => 'Name', 
    ), 
)); 
$this->add(array(
    'name' => 'notes', 
    'type' => 'Textarea', 
    'options' => array(
     'label' => 'Notes', 
    ), 
)); 

我如何可以指定一個寬度爲我的投入要素,屬性cols和rows爲我的textarea的?

回答

2
$this->add(array(
    'name' => 'name', 
    'type' => 'Text', 
    'options' => array(
     'label' => 'Name', 
    ), 
    'attributes' => array 
     (
     'maxlength' => 250, 
     'type' => 'text', 
     'class' => 'class-name' 
    ), 
)); 

您可以添加一個attributes數組,並指定一個可用於編輯輸入元素寬度的類。我相信你也可以爲此添加「行」和「列」。

+2

我認爲這種方式更好,因爲我的表單不需要知道如何呈現它。 CSS將完成以下工作: 'class-name input {width:15em;}'''''class-name textarea {width:60em;高度:7em;}'=>它的工作原理。 –