Zend 框架 - Zend_Form 装饰器问题 [英] Zend Framework - Zend_Form Decorator Issue

查看:31
本文介绍了Zend 框架 - Zend_Form 装饰器问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像这样扩展 Zend_Form 的类(简化):

I have a class that extends Zend_Form like this (simplified):

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);
    }
}

然后我使用那个类来创建我的所有表单:

I then use that class to create all of my forms:

class ExampleForm extends Core_Form
{
    public function init()
    {
        // Example Field
        $example = new Zend_Form_Element_Hidden('example');
        $this->addElement($example);
    }
}

在我的一个视图中,我需要显示这一字段(没有 Zend_Form 生成的任何其他内容).所以在我看来,我有这个:

In one of my views, I have a need to display only this one field (without anything else generated by Zend_Form). So in my view I have this:

<?php echo $this->exampleForm->example; ?>

这很好用,除了它生成这样的字段:

This works fine, except for it generates the field like this:

<li><input type="hidden" name="example" value=""></li>

这显然是因为我将元素装饰器设置为包含 HtmlTag: tag => 'li'.

This is obviously because I set the element decorators to include HtmlTag: tag => 'li'.

我的问题是:如何禁用此元素的所有装饰器.我不需要隐藏输入元素的装饰器.

推荐答案

最好设置的地方是 public function loadDefaultDecorators()

the best place to set it is public function 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'));
        }
    }

这篇关于Zend 框架 - Zend_Form 装饰器问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆