在 Zend Framework 中向文本字段添加美元符号 [英] Adding a dollar sign to a text field in Zend Framework

查看:27
本文介绍了在 Zend Framework 中向文本字段添加美元符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 Zend_Form 元素的 之前添加$"?(当然,使用标准的 ZF 东西会很棒).

Is there a way to add a "$" right before the <input> for a Zend_Form element? (using standard ZF stuff would be great, of course).

EDIT:例如,如果 Zend_Form 为 cost 元素生成的 html 类似于:(非常简化)

EDIT: For example, if the html generated by Zend_Form for a cost element is something like: (very simplified)

<label>Cost:</label>
<input type="text" name="cost" />

我希望它输出这个:

<label>Cost:</label>
$ <input type="text" name="cost" />

推荐答案

您可以使用 callback 装饰器,将您想要的任何 html 放入元素中:

You can use callback decorator to put whatever html you want in your elements:

例如在你的情况下,我可以这样做:

For example in your case I could do:

    $el1 = $this->createElement('text', 'el1')->setLabel('Cost:');

    // Anonymous function that will generate your custom html (needs PHP 5.3).
    // For older PHP there are other ways of making anonymous functions.
    $myHtml = function($content, $element, array $options) {
                return '$';
            };
    $el1->setDecorators(array(
        'ViewHelper',
        'Errors',
        array('Callback', array('callback' => $myHtml, 'placement' => 'PREPEND')),
        'Label'
    ));

这应该会产生以下 html 代码:

This should result in the following html code:

<label for="el1" class="optional">Cost:</label> 
$
<input type="text" name="el1" id="el1" value="" /> 

希望这将是有益的,或者至少为您指明了正确的方向.

Hope this will be helfull or at least point you in the right direction.

这篇关于在 Zend Framework 中向文本字段添加美元符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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