据我所知,这两者都用于创建链接:
Cakephp中的$this->Html->url和$this->Html链接之间的主要区别是什么?
使用这些是否会出现性能问题?
如果我想使用"$this->Html->url"在新选项卡中打开链接,该怎么办
我尝试过的:
<?php echo $this->Html->url($item['News']['link'],array('target'=>'_blank', 'escape' => false)); ?>
但它不起作用。打开同一选项卡中的链接。
提前谢谢。
根据CakePHP文档,HTML->url有两个参数,第二个是布尔值,而第一个是路由数组。试试这个:
<?php echo
$this->Html->url(
array(
'href' => $item['News']['link'],
'target' => '_blank',
'escape' => false
),
false // Second argument, true means prepend the path of my site before the link while false means don't prepend
); ?>
参考文献:
- http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::url
- http://book.cakephp.org/2.0/en/appendices/glossary.html#term-路由阵列
这就是$this->Html->link()
方法的作用。它采用一组选项作为参数来实现这一点。