【问题标题】:Difference between $this->Html->url and $this->Html->link in CakephpCakephp 中 $this->Html->url 和 $this->Html->link 的区别
【发布时间】:2014-09-28 11:05:13
【问题描述】:

据我所知,这两者都用于创建链接:

Cakephp中$this->Html->url$this->Html->link的主要区别是什么?

使用这些会出现性能问题吗?

如果我想使用“$this->Html->url”在新标签中打开链接怎么办

我尝试了什么:

<?php echo $this->Html->url($item['News']['link'],array('target'=>'_blank', 'escape' => false)); ?>

但它不起作用。在同一标签中打开链接。

提前致谢。

【问题讨论】:

  • 这就像问苹果和树有什么区别。另一个需要另一个存在;)在这种情况下,链接()需要 url() 才能存在和运行。

标签: php cakephp cakephp-2.0 cakephp-2.1 cakephp-2.3


【解决方案1】:

好吧,根据 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
     ); ?>

参考资料:

  1. http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::url
  2. http://book.cakephp.org/2.0/en/appendices/glossary.html#term-routing-array

【讨论】:

  • 你能在评论中粘贴它生成的内容吗?
【解决方案2】:

这就是$this-&gt;Html-&gt;link() 方法的用途。它需要一组选项作为参数来执行此操作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-06
    • 1970-01-01
    • 2011-04-07
    • 2015-01-01
    • 1970-01-01
    • 2012-10-31
    • 2023-02-13
    • 1970-01-01
    相关资源
    最近更新 更多