lee*_*eek 4 php zend-framework zend-form
我有一个扩展Zend_Form这样的类(简化):
class Core_Form extends Zend_Form
{
protected static $_elementDecorators = array(
'ViewHelper',
'Errors',
array('Label'),
array('HtmlTag', array('tag' => 'li')),
);
public function loadDefaultDecorators()
{
$this->setElementDecorators(self::$_elementDecorators);
}
}
Run Code Online (Sandbox Code Playgroud)
然后,我使用该类创建所有表单:
class ExampleForm extends Core_Form
{
public function init()
{
// Example Field
$example = new Zend_Form_Element_Hidden('example');
$this->addElement($example);
}
}
Run Code Online (Sandbox Code Playgroud)
在我的一种观点中,我只需要显示这一字段(Zend_Form不会生成任何其他内容)。所以我认为我有:
<?php echo $this->exampleForm->example; ?>
Run Code Online (Sandbox Code Playgroud)
这工作正常,除了它会生成如下所示的字段:
<li><input type="hidden" name="example" value=""></li>
Run Code Online (Sandbox Code Playgroud)
这显然是因为我将元素装饰器设置为包括HtmlTag:tag =>'li'。
我的问题是:如何禁用此元素的所有装饰器。隐藏的输入元素不需要装饰器。
设置它的最佳位置是公共函数loadDefaultDecorators()
例如这样的:
class ExampleForm extends Core_Form
{
public function init()
{
//Example Field
$example = new Zend_Form_Element_Hidden('example');
$this->addElement($example);
}
public function loadDefaultDecorators()
{
$this->example->setDecorators(array('ViewHelper'));
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6053 次 |
| 最近记录: |