zend-framework - 在 Zend_Form_Element 描述装饰器中使用 HTML

标签 zend-framework zend-form-element zend-decorators

是否可以在 Zend_Form_Elment 的描述装饰器中使用 HTML?例如,以下语句不起作用:

$number = new Zend_Form_Element_Text('number', array(
       'size' => 32,
       'description' => 'Please the the following website: <a href="foo/bar">lorem ipsum</a>',
       'max_length' => 100,
       'label' => 'Number'));

描述中未显示链接,括号将转换为其特殊字符对应项。

是否有其他方法来显示链接(或根本使用 HTML...)?

最佳答案

这是可能的,您只需告诉 Description 装饰器不要转义输出即可。

尝试:

$number = new Zend_Form_Element_Text('number', array(
   'size'        => 32,
   'description' => 'Please the the following website: <a href="foo/bar">lorem ipsum</a>',
   'max_length'  => 100,
   'label'       => 'Number')
);

$number->getDecorator('Description')->setOption('escape', false);

如果您为元素创建自己的一组装饰器,则也可以在配置装饰器时指定此选项,如下所示:

    $elementDecorators = array(
        'ViewHelper',
        'Errors',
        array('Description', array('class' => 'description', 'escape' => false)),
        array('HtmlTag',     array('class' => 'form-div')),
        array('Label',       array('class' => 'form-label', 'requiredSuffix' => '*'))
);

相关部分是:

array('Description', array('class' => 'description', 'escape' => false)),

关于zend-framework - 在 Zend_Form_Element 描述装饰器中使用 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11415659/

相关文章:

php - 如何以编程方式隐藏 Zend_Element_Checkbox 的字段和标签?

zend-framework - Zend Framework 1.10中Captcha元素的自定义错误消息

php - 提交失败后如何装饰表单 ZF 1.12

php - 文件输入的困难装饰器

php - Zend Framework - 找不到 'LEV' 货币

zend-framework - 如何从 Zend Framework 模型类名称中删除 "Application_Model_"前缀?

php - 将 Zend Framework 从版本 X 升级到版本 Y

php - zend 表单验证

php - 以 zend 框架的形式设置选定值

zend-framework - 使用 zend-decorator 将表格列中的 Zend_Form_Element_Radio 格式化为行中的其他 Zend 表单元素