下面是Zend Framework 2.0的示例,现在正在编写Forms一章。除了我的"密码"answers"确认密码"字段似乎没有正确呈现之外,一切似乎都很好。以下是我的RegisterForm.php
文件的摘录,我在其中定义密码字段
class RegisterForm extends Form
{
public function __construct($name = null)
{
parent::__construct('Register');
$this->setAttribute('method', 'post');
$this->setAttribute('enctype', 'multipart/form-data');
...
$this->add(array(
'name' => 'password',
'attributes' => array(
'type' => 'password',
),
'options' => array(
'label' => 'Password',
),
'attributes' => array(
'required' => 'required'
),
'filters' => array(
array('name' => 'StringTrim'),
),
));
但是当它在浏览器中呈现时,当我查看页面源时,我会得到这个。。。
<dd><input name="password" required="required" type="text" value=""></dd>
我很确定我已经正确地从书中得到了代码,但我不确定是否还有另一个步骤我意外地重写了RegisterForm.php文件。
为什么要覆盖属性?应该是:
$this->add(array(
'name' => 'password',
'options' => array(
'label' => 'Password',
),
'attributes' => array(
'type' => 'password',
'required' => 'required'
),
'filters' => array(
array('name' => 'StringTrim'),
),
));
'attributes' => array(
'type' => 'password',
),
// ...
'attributes' => array(
'required' => 'required'
),
想一想。。。