在 zend 框架中放置元标记、链接和样式的最佳实践?
我有需要设置的项目范围元标记。 我已将它们放入 Bootstrap
类中的受保护方法 _initMeta
中。 还有更好的选择吗?如果我想要其他语言的不同数据集怎么办?
protected function _initMeta(){
$this->bootstrap('view');
$view = $this->getResource('view');
$view->doctype('XHTML1_STRICT');
$view->headTitle()->headTitle('Foo title');
$view->headMeta()->appendName('keywords','foo');
$view->headMeta()->appendHttpEquiv('Content-Type', 'text/html; charset=UTF-8')
->appendHttpEquiv('Content-Language', 'any');
$view->headLink()->appendStylesheet('/foo.css')->headLink(array('rel' => 'favicon',
'href' => '/favicon.ico'),
'PREPEND');
}
I have project-range meta tags that are need to be set.
I've put them in protected method _initMeta
in Bootstrap
class.
Are there any better options? What if I would like different set of this data for another languages?
protected function _initMeta(){
$this->bootstrap('view');
$view = $this->getResource('view');
$view->doctype('XHTML1_STRICT');
$view->headTitle()->headTitle('Foo title');
$view->headMeta()->appendName('keywords','foo');
$view->headMeta()->appendHttpEquiv('Content-Type', 'text/html; charset=UTF-8')
->appendHttpEquiv('Content-Language', 'any');
$view->headLink()->appendStylesheet('/foo.css')->headLink(array('rel' => 'favicon',
'href' => '/favicon.ico'),
'PREPEND');
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我使用基本(引导)数据的配置为:
application.ini
此时,也许您有一些特殊数据。例如在:
project1.ini
最后,将所有内容混合在
Bootstrap.php
中(例如 *_initHeadLink()*):
然后,您可以从控制器覆盖这些数据:setName、set...
我希望它有所帮助; )
I use config for basic (bootstrap) data as:
application.ini
At this point, maybe you have some special data. For example in:
project1.ini
And finally, you mix all in your
Bootstrap.php
(example for *_initHeadLink()*):
Then, you can override these data from your Controller: setName, set...
I hope it helps ;)
您有多种方法可以实现这一目标。首先也是最重要的,确保在定义元数据时您已经知道将为当前请求加载哪种语言。有时这在引导时可能不容易确定。
话虽如此,除了引导程序之外,您还可以在以下位置设置元数据:
在这些执行点,您可能已经确定要使用的语言,并且可以相应地设置元数据。之后您可以随时在操作控制器中更改特定的元数据案例在您的应用程序中,因此如果您之前指定了元数据,您永远不会真正陷入困境。
在我自己的工作中,我有这样的设置:
这个安排对我来说很有意义,也许它可以帮助你的方法?
You have several ways of achieving this. First and foremost, make sure the moment you define the metadata you already know what language will be loaded for the current request. Sometimes this may not be easy to determine at bootstrap time.
Having said this, besides the bootstrap, you can set the metadata on a:
At those points of execution you probably already determined the language to use, and can set the metadata accordingly. You can always change the metadata afterwards in your action controllers for specific cases in your application, so you're never really stuck if you previously specified metadata.
In my own work, I have this setup:
This arrangement makes sense to me, maybe it can help your approach?
对于我的项目来说,引导程序还为时过早。我将它们添加到我的控制器/操作中
实际上很晚,几乎在最后。在这一点上我也会了解语言和其他事情。
The bootstrap is way to early for my projects. I add them in my controller/actions
Actually very late almost at the end. At this point I would also know about language and other things.