一个Zend_Form的完整装饰
-
1
class My_Form_Registration extends Zend_Form
2
{
3
public $elementDecorators = array(
4
'ViewHelper',
5
'Errors',
6
array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),
7
array('Label', array('tag' => 'td'),
8
array(array('row' => 'HtmlTag'), array('tag' => 'tr')),
9
);
10
11
public $buttonDecorators = array(
12
'ViewHelper',
13
array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),
14
array(array('label' => 'HtmlTag'), array('tag' => 'td', 'placement' => 'prepend')),
15
array(array('row' => 'HtmlTag'), array('tag' => 'tr')),
16
);
17
18
public function init()
19
{
20
$this->addElement('text', 'username', array(
21
'decorators' => $this->elementDecorators,
22
'label => 'Username:',
23
);
24
$this->addElement('text', 'firstname', array(
25
'decorators' => $this->elementDecorators,
26
'label => 'First Name:',
27
);
28
$this->addElement('text', 'lastname', array(
29
'decorators' => $this->elementDecorators,
30
'label => 'Last Name:',
31
);
32
$this->addElement('submit', 'save', array(
33
'decorators' => $this->buttonDecorators,
34
'label => 'Save',
35
);
36
}
37
38
public function loadDefaultDecorators()
39
{
40
$this->setDecorators(array(
41
'FormElements',
42
array('HtmlTag', array('tag' => 'table')),
43
'Form',
44
));
45
}
46
}
47
class My_Form_Registration extends Zend_Form2
{3
public $elementDecorators = array(4
'ViewHelper',5
'Errors',6
array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),7
array('Label', array('tag' => 'td'),8
array(array('row' => 'HtmlTag'), array('tag' => 'tr')),9
);10

11
public $buttonDecorators = array(12
'ViewHelper',13
array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),14
array(array('label' => 'HtmlTag'), array('tag' => 'td', 'placement' => 'prepend')),15
array(array('row' => 'HtmlTag'), array('tag' => 'tr')),16
);17

18
public function init()19
{20
$this->addElement('text', 'username', array(21
'decorators' => $this->elementDecorators,22
'label => 'Username:',23
);24
$this->addElement('text', 'firstname', array(25
'decorators' => $this->elementDecorators,26
'label => 'First Name:',27
);28
$this->addElement('text', 'lastname', array(29
'decorators' => $this->elementDecorators,30
'label => 'Last Name:',31
);32
$this->addElement('submit', 'save', array(33
'decorators' => $this->buttonDecorators,34
'label => 'Save',35
);36
}37

38
public function loadDefaultDecorators()39
{40
$this->setDecorators(array(41
'FormElements',42
array('HtmlTag', array('tag' => 'table')),43
'Form',44
));45
}46
}47

浙公网安备 33010602011771号