将元标记,链接和样式放置在zend框架中的最佳实践? [英] Best practice to place meta tags, links and styles in zend framework?

查看:75
本文介绍了将元标记,链接和样式放置在zend框架中的最佳实践?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有需要设置的项目范围的元标记. 我将它们放在Bootstrap类的受保护方法_initMeta中. 有没有更好的选择?如果我想要另一种语言的不同数据集怎么办?

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');
}

推荐答案

我将config用于基本(引导)数据的方式为:

I use config for basic (bootstrap) data as:

resources.view.meta.name.Viewport                       = "width=device-width, initial-scale=1.0"
resources.view.meta.name.MobileOptimized                    = "width"
resources.view.meta.name.HandheldFriendly                   = "true"
resources.view.meta.name.Keywords                       = "basic,keywords"
...
; format resources.view.headStyle.{MEDIA}.nfile = 
resources.view.headStyle.all.1.href                 = "/css/basic.css"
resources.view.headStyle.all.1.conditionalStylesheet            = 
resources.view.headStyle.all.1.extras.title             = "Basic style"
resources.view.headStyle.all.1.extras.charset               = "utf-8"

resources.view.headStyle.all.2.href                 = "/css/ie.css"
resources.view.headStyle.all.2.conditionalStylesheet            = "IE"
resources.view.headStyle.all.2.extras.title             = "Internet Explorer style"
resources.view.headStyle.all.2.extras.charset               = "utf-8"
; print media example
resources.view.headStyle.print.1.href                   = "/css/print.css"
...
; format resources.view.headLink.{REL} = 
resources.view.headLink.humans.href                     = "/humans.txt"
resources.view.headLink.humans.type                     = "text/plain"
; ___ will be replaced by space, __ by point (or set another nest separator)
resources.view.headLink.shortcut___icon.href                = "/favicon.png"
resources.view.headLink.shortcut___icon.type                = "image/png"
...

在这一点上,也许您有一些特殊的数据.例如:

At this point, maybe you have some special data. For example in:

project.headLink.author.href                = "https://plus.google.com/XXXXX?rel=author"
project.headLink.image_src.href                     = "/author.jpg"
project.headLink.image_src.type                     = "image/jpg"

最后,您将所有内容混在一起

And finally, you mix all in your

(* _ initHeadLink()*的示例):

(example for *_initHeadLink()*):

// $options = your app options (basic)
// $projectOptions = your project options (special)
// $assets_url = your assets url

if ( is_array($headStyle = $options['headStyle']) ) {
    foreach ( $headStyle as $media => $value ) {
        foreach ( $value as $style ) {
            extract($style);
            $this->view->headLink()->appendStylesheet($assets_url . $href, $media, 
                            $conditionalStylesheet, $extras);
        }
    }
}

$headLinks      = array();

if ( isset($options['headLink']) ) 
    $headLinks      = $options['headLink'];

if ( isset($projectOptions['headLink']) ) 
    $headLinks      = array_merge($headLinks, (array) $projectOptions['headLink']);

// *array key, is the value for rel
foreach ( $headLinks as $rel => $value ) {
    $rel            = str_replace(array('___', '__'), array(' ', '.'), $rel);
    $this->view->headLink()->headLink(array_merge(array('rel' => $rel), (array) $value));
}

然后,您可以从Controller覆盖以下数据:setName,set ...

Then, you can override these data from your Controller: setName, set...

我希望它会有所帮助;)

I hope it helps ;)

这篇关于将元标记,链接和样式放置在zend框架中的最佳实践?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆