【问题标题】:Zend Form Decorators issueZend 表单装饰器问题
【发布时间】:2013-03-24 12:36:08
【问题描述】:

*我的英语说得不好。所以我现在要发布代码。*

表格代码:

protected $elementDecorators = array('ViewHelper','Errors','Description','Label',
            array('HtmlTag',array('tag' => 'div','class' => '_wrapperElement')          
            ));

    public function init(){
        $this->addElement('text','mytext',array(
        'class' => '_inputText',
        'label' => 'Mytext',
        'required' => true,
        'decorators' => $this->elementDecorators
        ));

        $this->setDecorators(array('FormElements',array('HtmlTag',array('tag' => 'div','class' => '_formWrapper')),'Form'));

    }

输出:

<form method="post" action="" enctype="application/x-www-form-urlencoded">
    <div class="_formWrapper">
        <div class="_wrapperElement">
            <label class="required" for="mytext">Mytext</label>
            <input type="text" class="_inputText" value="" id="mytext" name="mytext">    
        </div>
    </div>
</form>

现在我想要一个 div 包装标签和输入元素,如下所示:

<form method="post" action="" enctype="application/x-www-form-urlencoded">
    <div class="_formWrapper">
        <div class="_wrapperElement">
            <div class="_wrapperLabel">
                <label class="required" for="mytext">Mytext</label>
            </div>
            <div class="_wrapperInput">
                <input type="text" class="_inputText" value="" id="mytext" name="mytext">    
            </div>
        </div>
    </div>
</form>

怎么做?

我试了很多次都做不到。

谢谢!

【问题讨论】:

    标签: forms zend-framework zend-decorators


    【解决方案1】:
    protected $elementDecorators = array('ViewHelper','Errors','Description', array('Label', array('tag' => 'div', 'class' => '_wrapperLabel')
            ),
                array('HtmlTag',array('tag' => 'div','class' => '_wrapperInput')          
                ));
    

    【讨论】:

      【解决方案2】:

      我找到了将装饰器渲染到 ViewScript 的解决方案。

      【讨论】:

        猜你喜欢
        • 2011-01-10
        • 2011-01-10
        • 2011-07-09
        • 2012-10-23
        • 1970-01-01
        • 1970-01-01
        • 2011-07-13
        • 2011-01-24
        • 2011-06-24
        相关资源
        最近更新 更多