为什么我们在 cakephp 中使用 escape => false
Why we use escape => false in cakephp
echo $this->Html->link(
'<span class="glyphicon glyphicon-remove"></span> Cancel',
array(
'action'=>'index',
'page:'.$this->request->data['Transaction']['page']
),
array(
'class'=>'btn btn-default',
'escape'=>false
),
'Do you want to cancel ?'
);
HTML $title
中的特殊字符将被转换为 HTML 个实体。要禁用此转换,我们在 $options
数组中将转义选项设置为 false:
$this->Html->link($title, $url, $options);
阅读:Manual
因为你的标签是HTML而不是纯文本。
您不想插入文字 <span class="glyphicon glyphicon-remove"></span>
文本,您希望 HTML 标签显示图标。
// lib/Cake/View/Helper/HtmlHelper.php
if (isset($options['escapeTitle'])) {
$escapeTitle = $options['escapeTitle'];
unset($options['escapeTitle']);
} elseif (isset($options['escape'])) {
$escapeTitle = $options['escape'];
}
if ($escapeTitle === true) {
$title = h($title);
} elseif (is_string($escapeTitle)) {
$title = htmlentities($title, ENT_QUOTES, $escapeTitle);
}
所有 HTML 字符默认情况下会在视图上转义,就像您在其上使用 htmlentities()
一样,因此,由于这个原因,CakePHP Helpers ($this->Html->link()
创建的所有元素在这种情况下)需要参数 'escape' => false
来避免这种转换,无论是尝试使用嵌套标签还是在标签中嵌套 HTML 左右。
echo $this->Html->link(
'<span class="glyphicon glyphicon-remove"></span> Cancel',
array(
'action'=>'index',
'page:'.$this->request->data['Transaction']['page']
),
array(
'class'=>'btn btn-default',
'escape'=>false
),
'Do you want to cancel ?'
);
HTML $title
中的特殊字符将被转换为 HTML 个实体。要禁用此转换,我们在 $options
数组中将转义选项设置为 false:
$this->Html->link($title, $url, $options);
阅读:Manual
因为你的标签是HTML而不是纯文本。
您不想插入文字 <span class="glyphicon glyphicon-remove"></span>
文本,您希望 HTML 标签显示图标。
// lib/Cake/View/Helper/HtmlHelper.php
if (isset($options['escapeTitle'])) {
$escapeTitle = $options['escapeTitle'];
unset($options['escapeTitle']);
} elseif (isset($options['escape'])) {
$escapeTitle = $options['escape'];
}
if ($escapeTitle === true) {
$title = h($title);
} elseif (is_string($escapeTitle)) {
$title = htmlentities($title, ENT_QUOTES, $escapeTitle);
}
所有 HTML 字符默认情况下会在视图上转义,就像您在其上使用 htmlentities()
一样,因此,由于这个原因,CakePHP Helpers ($this->Html->link()
创建的所有元素在这种情况下)需要参数 'escape' => false
来避免这种转换,无论是尝试使用嵌套标签还是在标签中嵌套 HTML 左右。