Zend framework Zend Form decorators的麻烦
如何使用表单元素的表单装饰器实现以下目标:Zend framework Zend Form decorators的麻烦,zend-framework,zend-form,decorator,Zend Framework,Zend Form,Decorator,如何使用表单元素的表单装饰器实现以下目标: <dt> <ul> <li>The errors</li> <li>The errors</li> </ul> <label>The label</label> </dt> <dd> <input type="text" value="The input field"> <
<dt>
<ul>
<li>The errors</li>
<li>The errors</li>
</ul>
<label>The label</label>
</dt>
<dd>
<input type="text" value="The input field">
</dd>
- 错误
- 错误
标签
换句话说,我希望在标签前面加上错误,而不是在输入字段后面加上错误。但是,我确实希望保留如上所示的
和
标记。在表单类中,尝试以下操作:
$this->setElementDecorators(array(
'Errors',
'ViewHelper',
'Label',
));
好吧,我知道怎么做了。渐渐地,装饰师开始对我有意义了:
$decorators = array(
'Label',
array( 'Errors', array( 'placement' => 'prepend' ) ),
array( array( 'dt' => 'HtmlTag' ), array( 'tag' => 'dt' ) ),
array( array( 'ddOpen' => 'HtmlTag' ), array( 'tag' => 'dd', 'openOnly' => true, 'placement' => 'append' ) ),
array( 'ViewHelper' ),
array( array( 'ddClose' => 'HtmlTag' ), array( 'tag' => 'dd', 'closeOnly' => true, 'placement' => 'append' ) )
);
其作用如下:
// be sure to only set them, after you have added the relevant elements to the form
$this->setElementDecorators( $decorators );
PS:请注意,我的特定示例会生成无效的html。;-)我后来才发现
元素不允许出现在
DOCTYPE的
元素中,恐怕这并不能解决这个问题。这会导致
,而没有
和
确保您接受您的答案,因此它显示为已解决:)