2011-03-15 121 views
5

我怎样才能创建这个使用HTML帮手? (内联= false,这样我就可以在每个视图的基础上指定它)CakePHP标准标签与HTML帮助

<link rel="canonical" href="http://www.example.com/product.php?item=swedish-fish" /> 

似乎无法找到这样的东西,除了不工作的修补程序。

回答

7

看来我的朋友刚刚告诉我,我告诉他怎么做这个几个月前,问题就解决了......

<?php echo $this->Html->meta('canonical', 
    'http://www.example.com/product.php?item=swedish-fish', 
    array('rel'=>'canonical', 'type'=>null, 'title'=>null, 'inline' => false) 
);?> 
+1

不要忘记'echo $ this-> fetch('meta');'在布局中。 – bancer 2014-01-30 14:01:46

1

如果你正在寻找的东西,自动把当前的URL输出到一个规范的标签,你可以使用$this->Html->url(null, true);$this->here;在CakePHP的html helper中。

<?php echo $this->Html->meta('canonical', $this->Html->url(null, true), array('rel'=>'canonical', 'type'=>null, 'title'=>null)); ?> 

或者

<?php echo $this->Html->meta('canonical', $this->here, array('rel'=>'canonical', 'type'=>null, 'title'=>null)); ?> 

警告: 我听到的一些情况$this->here对本地开发环境的问题。

0

在CakePHP 2:

echo $this->Html->meta('canonical', 'http://example.com', array('rel' => 'canonical', 'type' => null, 'title' => null, 'inline' => false)); 

在CakePHP 3:

echo $this->Html->meta('canonical', 'http://example.com', array('rel' => 'canonical', 'type' => null, 'title' => null, 'block' => true)); 

注意,版本之间的主要区别在于,CakePHP的2使用'inline' => false而CakePHP的3使用'block' => true到文档内放置这些<head>标签。