【问题标题】:Render Zend\Form\Element\Button with content and without label渲染 Zend\Form\Element\Button 有内容但没有标签
【发布时间】:2012-10-26 10:42:23
【问题描述】:

似乎无法使用不带标签的 FormCollection 视图助手自动呈现按钮元素。

只要有可能,我都会以这种方式呈现表单:

<?php echo $this->form()->openTag($this->form); ?>
    <?php echo $this->formCollection($this->form); ?>
<?php echo $this->form()->closeTag($this->form); ?>

但是,FormCollection 调用的 FormButton 视图助手等待按钮的内容作为 render() 方法的第二个参数 - 或标签选项。如果我设置标签,按钮会正确呈现,但是,你猜对了,带有标签。

我试图通过浏览代码找出解决方法,但我看不到。

注意: FormButton 呈现&lt;button&gt;...&lt;/button&gt; 元素。我也可以使用&lt;input type="button" /&gt; 元素。

我在这里遗漏了什么吗?提前致谢!

【问题讨论】:

    标签: php button zend-form zend-framework2


    【解决方案1】:

    当我为这个问题苦苦挣扎时,我不小心得到了解决方案!它是如此简单(或骇人听闻?),以至于我没想过要工作。

    将此添加到您的字段集:

    $this->add(array(
        'name' => 'delete',
        'attributes' => array('type'=>'button', 'value' => 'Delete', 'onclick'=>'delete()'),
    ));
    

    就是这样。它对我很有效。

    【讨论】:

    • 这个解决方案对我有用。快捷方便。谢谢!
    【解决方案2】:

    编写您自己的 formCollection ViewHelper,使用您自己的 formButton ViewHelper。

    【讨论】:

    • 是的,这是最明显的解决方案,但是,我想知道是否有本地方式。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-27
    • 2018-04-05
    • 2021-04-16
    • 2019-10-14
    相关资源
    最近更新 更多