带 html 帮助器的 CakePHP Canonical 标签
我如何使用 html 帮助器创建它? (使用 inline=false ,这样我就可以在每个视图的基础上指定它)
<link rel="canonical" href="http://www.example.com/product.php?item=swedish-fish" />
除了不起作用的补丁之外,似乎找不到任何相关内容。
How can I create this using the html helper? (with inline=false so i can specify it on a per-view basis)
<link rel="canonical" href="http://www.example.com/product.php?item=swedish-fish" />
Can't seem to find anything on this, apart from a patch that doesn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在 CakePHP 错误跟踪网站中找到了这个: http://cakephp.lighthouseapp.com/projects/42648/tickets/1063-support-for-custom-meta-tag-elements-in-htmlhelper
显然你可以使用
Found this in CakePHP bugtracking site : http://cakephp.lighthouseapp.com/projects/42648/tickets/1063-support-for-custom-meta-tag-elements-in-htmlhelper
Apparently you can use
好像我的朋友刚刚告诉我,几个月前我告诉他如何做到这一点,问题解决了......
It seems my friend just told me that I told him how to do this a few months back, problem solved...
如果您正在寻找自动将当前 url 输出到规范标记中的东西,您可以使用
$this->Html->url(null, true);
或$ Cakephp html 帮助程序中的 this->here;
。或者
警告:
我听说过一些情况,其中
$this->here
在本地开发环境中存在问题。If you're looking for something that automatically outputs the current url into a canonical tag, you can use the
$this->Html->url(null, true);
or$this->here;
within the Cakephp html helper.Or
WARNING:
I have heard of some cases where
$this->here
has issues on local dev environments.在 CakePHP 2 中:
在 CakePHP 3 中:
请注意,版本之间的主要区别是 CakePHP 2 使用
'inline' => 。 false
而 CakePHP 3 使用'block' =>; true
将它们放置在文档标记中。
In CakePHP 2:
In CakePHP 3:
Note that the main difference between versions is that CakePHP 2 uses
'inline' => false
whereas CakePHP 3 uses'block' => true
to place these within the document<head>
tags.在 CakePHP 4 中:
在您的视图中(例如:Articles/view.php)添加以下内容:
然后使用以下指令将其打印在您的layout/default.ctp中
In CakePHP 4:
In your view (es: Articles/view.php) add this:
Then you print it in your layout/default.ctp with this instruction