2

是否可以在 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 ......)?

4

1 回答 1

4

有可能,您只需要告诉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' => '*'))
);

相关部分是:

数组('描述',数组('类' => '描述','转义' => false)),

于 2012-07-10T17:22:22.193 回答