我怎样才能创建这个使用HTML帮手? (内联= false,这样我就可以在每个视图的基础上指定它)CakePHP标准标签与HTML帮助
<link rel="canonical" href="http://www.example.com/product.php?item=swedish-fish" />
似乎无法找到这样的东西,除了不工作的修补程序。
我怎样才能创建这个使用HTML帮手? (内联= false,这样我就可以在每个视图的基础上指定它)CakePHP标准标签与HTML帮助
<link rel="canonical" href="http://www.example.com/product.php?item=swedish-fish" />
似乎无法找到这样的东西,除了不工作的修补程序。
看来我的朋友刚刚告诉我,我告诉他怎么做这个几个月前,问题就解决了......
<?php echo $this->Html->meta('canonical',
'http://www.example.com/product.php?item=swedish-fish',
array('rel'=>'canonical', 'type'=>null, 'title'=>null, 'inline' => false)
);?>
CakePHP中的bug跟踪网站上发现这一点:http://cakephp.lighthouseapp.com/projects/42648/tickets/1063-support-for-custom-meta-tag-elements-in-htmlhelper
显然你可以使用
echo $this->Html->meta('canonical', 'http:://example.com', array('rel'=>'canonical', 'type'=>null, 'title'=>null));
//outputs <link href="http:://example.com" rel="canonical" />
如果你正在寻找的东西,自动把当前的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
对本地开发环境的问题。
在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>
标签。
不要忘记'echo $ this-> fetch('meta');'在布局中。 – bancer 2014-01-30 14:01:46