CakePHP Canonical Tag with html helper

如何使用html帮助器创建它? (使用inline = false,因此我可以基于每个视图指定它)
<link rel="canonical" href="http://www.example.com/product.php?item=swedish-fish" />
似乎无法找到任何东西,除了一个不起作用的补丁。     
已邀请:
在CakePHP bugtracking网站上找到了这个: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" />
    
好像我的朋友告诉我,几个月前我告诉他如何做到这一点,问题解决了......
<?php echo $this->Html->meta('canonical', 
    'http://www.example.com/product.php?item=swedish-fish', 
    array('rel'=>'canonical', 'type'=>null, 'title'=>null, 'inline' => false)
);?>
    
如果您正在寻找能够自动将当前url输出到规范标签的内容,您可以在Cakephp html帮助器中使用
$this->Html->url(null, true);
$this->here;
<?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>
标签中。     

要回复问题请先登录注册