【问题标题】:overwrite specific Decorators for all Zend_Form Objects覆盖所有 Zend_Form 对象的特定装饰器
【发布时间】:2011-06-28 15:00:27
【问题描述】:

我正在为一个项目设计样式,每个人都使用 Zend_Form 和默认元素。这使得无法设置提交按钮的样式。 因此,我想覆盖提交按钮的默认 Zend_Form 装饰器,但不更改创建 Zend_Form 的每一行。

这可能吗? 如果是,怎么做?

【问题讨论】:

    标签: php zend-form decorator zend-decorators


    【解决方案1】:

    您可能希望继承 Zend_Form_Element_Submit 并使用 loadDefaultDecorators() 为您的提交设置默认装饰器:

    class My_Form_Element_Submit extends Zend_Form_Element_Submit
    {
        public function loadDefaultDecorators()
        {
            // set your default decorators for the submit element       
            $decorators = $this->getDecorators();
            if (empty($decorators)) {
                $this->setDecorators(array(
                    'ViewHelper',
                    array(
                        array('field' => 'HtmlTag'),
                        array(
                            'tag'   => 'span',
                            'class' => 'some-wrapper-class'
                        ) 
                    )
                ));
            }
        }
    }
    

    上面的装饰器会导致 HTML 代码看起来像这样,让您可以轻松地设置提交按钮的样式:

    <span class="some-wrapper-class"> 
        <input type="submit" name="save" id="save" value="Save">
    </span> 
    

    【讨论】:

    • 不,子类化并不是我想要的。
    • @Andresch 为什么会这样?如果您提供不符合您要求的原因,我或其他人可以更好地帮助您。
    • 对不起@Aron Rotteveel 我弄错了。其实这就是我一直在寻找的。的种类。谢谢。
    猜你喜欢
    • 1970-01-01
    • 2012-04-20
    • 1970-01-01
    • 1970-01-01
    • 2011-10-25
    • 1970-01-01
    • 1970-01-01
    • 2015-02-07
    • 1970-01-01
    相关资源
    最近更新 更多