在我的<;a>;标签,有很多HTML代码。如何添加Html链接(CakePHP)
我的代码:在我的<;a>;标签,有很多HTML代码。如何添加Html链接(CakePHP),cakephp,cakephp-2.0,cakephp-helper,Cakephp,Cakephp 2.0,Cakephp Helper,我的代码: <a href="#"> <div class="list_content"> <p class="title"><?php echo $note['Note']['title']; ?></p> <p class="create_at"><?php echo $note['Note']['create_at'] ?></p> <p> &
<a href="#">
<div class="list_content">
<p class="title"><?php echo $note['Note']['title']; ?></p>
<p class="create_at"><?php echo $note['Note']['create_at'] ?></p>
<p> <?php echo substr($note['Note']['content'], 0,100) . '...' ?></p>
</div>
</a>
如何在CAKEPHP 2.x中添加
如果要在任何HTML帮助程序中插入HTML元素,必须添加'escape'=>false。检查文件
简单示例:
$this->Html->link('<b>My Content</b>','#',[
'escape' => false
]);
如果您要使用Aman的答案,请记住,通过设置
'escape'=>false,您将禁用默认的安全功能。因此,您可能希望确保使用h()
方法转义任何用户输入:-
$this->Html->link(
$this->Html->div('list_content',
$this->Html->para('title', h($note['Note']['title'])).
$this->Html->para('create_at', h($note['Note']['create_at'])).
$this->Html->para(null, substr(h($note['Note']['content']), 0,100) . '...')
),
'#',
['escape' => false]
);
如果您的
我所知道的第二个示例的唯一真正缺点是,您丢失了可能添加到$this->Html->link()
的任何功能,但我怀疑这不是大多数用户关心的问题。如果禁用escape
,您应该记住使用h()
来转义任何用户输入。默认情况下,出于安全考虑,Cake会故意转义链接文本,因此禁用此功能需要小心!非常感谢,但我正在使用CKEditor添加内容注释。当在内容中有标记…,它将不会位于$this->Html->link(“…”)中。如何在$this->Html->link(“…”)中添加标记,请帮助我:
$this->Html->link(
$this->Html->div('list_content',
$this->Html->para('title', h($note['Note']['title'])).
$this->Html->para('create_at', h($note['Note']['create_at'])).
$this->Html->para(null, substr(h($note['Note']['content']), 0,100) . '...')
),
'#',
['escape' => false]
);
<a href="<?= $this->Html->url('#') ?>">
<div class="list_content">
<p class="title"><?php echo $note['Note']['title']; ?></p>
<p class="create_at"><?php echo $note['Note']['create_at'] ?></p>
<p> <?php echo substr($note['Note']['content'], 0,100) . '...' ?></p>
</div>
</a>