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);
}