Zend Framework headMeta() - 关键字未附加
我正在使用 Zend Framework 1.8。 我在 headMeta() 复制我的元关键字时遇到问题。
在我的layout.phtml中,我有headMeta(); ?>
我有一个自定义 Controller_Plugin_ViewSetup
(扩展 Zend_Controller_Plugin_Abstract
),其中包含以下代码,位于 dispatchLoopStartup()
中功能:$view->headMeta()->setHttpEquiv('Content-Type', 'text/html;charset=utf-8');
$view->headMeta()->setName('keywords', 'global,generic,keywords,');
最后,在我的视图脚本中,我有以下内容:$this->headMeta()->appendName('keywords', 'view,specific,keywords');
我期望在我的 HTML 源代码中,我会看到:
但是,我实际上看到了这一点:
换句话说,元关键字没有按应有的方式连接在一起。 我究竟做错了什么?
干杯,
马特
I'm using Zend Framework 1.8. I have a problem with headMeta() duplicating my meta keywords.
In my layout.phtml, I have<?php echo $this->headMeta(); ?>
I have a Custom Controller_Plugin_ViewSetup
(extending Zend_Controller_Plugin_Abstract
) that has the following code in it, in the dispatchLoopStartup()
function:$view->headMeta()->setHttpEquiv('Content-Type', 'text/html;charset=utf-8');
$view->headMeta()->setName('keywords', 'global,generic,keywords,');
Finally, in my view scripts, I have the following:$this->headMeta()->appendName('keywords', 'view,specific,keywords');
I was expecting that in my HTML source code, I would see:<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="keywords" content="global,generic,keywords,view,specific,keywords" />
However, I actually see this:<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="keywords" content="global,generic,keywords," />
<meta name="keywords" content="view,specific,keywords" />
In other words, the meta keywords aren't concatenating together as they should. What am I doing wrong?
Cheers,
Matt
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为追加方法不会将更多关键字附加到已定义的列表中。 append 方法会将下一个标签附加到已定义的标签中。 同样,如果您选择前置,这会将您的新标签添加到您在插件中定义的标签之前。
我认为,最好的办法是从插件中删除关键字占位符,并将默认关键字存储在配置对象中,并在添加其他关键字的同时将它们插入视图中。
That's because the append method doesn't append more key words to the list already defined. The append method will append the next tag to the tags already defined. Similarly, if you chose prepend, this would add your new tag before the one you defined in your plugin.
I think, the best thing to do, would be to remove the keywords place holder from the plugin and store your default keywords in your config object and insert these into your view at the same time that you add your additional keywords.