我正在填充一个 Select 表单元素,如果我尝试在值中使用 HTML 实体,它会被转换,而不是显示特殊字符。
这段代码:
$form->field_name->addMultiOption('value', ' • label');
渲染:
<option value="one">&nbsp;&bull; label</option>
但我希望它是:
<option value="one"> • label</option>
如何在此处使用 HTML 实体?
暗示?
我挖掘了代码,发现它使用标签和值escape()
上 Zend View Abstract 中的函数。也许有人知道如何为特定的表单元素覆盖/重载这个函数?我不想默认覆盖该行为。
Zend_View_Helper_FormSelect
类中的函数
protected function _build($value, $label, $selected, $disable)
{
if (is_bool($disable)) {
$disable = array();
}
$opt = '<option'
. ' value="' . $this->view->escape($value) . '"'
. ' label="' . $this->view->escape($label) . '"';
// selected?
if (in_array((string) $value, $selected)) {
$opt .= ' selected="selected"';
}
// disabled?
if (in_array($value, $disable)) {
$opt .= ' disabled="disabled"';
}
$opt .= '>' . $this->view->escape($label) . "</option>";
return $opt;
}
这是Zend_View_Abstract
类中的函数:
private $_escape = 'htmlspecialchars';
/* SNIP */
public function escape($var)
{
if (in_array($this->_escape, array('htmlspecialchars', 'htmlentities'))) {
return call_user_func($this->_escape, $var, ENT_COMPAT, $this->_encoding);
}
return call_user_func($this->_escape, $var);
}