php - Best practice to place meta tags, links and styles in zend framework? -
i have project-range meta tags need set. i've put them in protected method _initmeta
in bootstrap
class. there better options? if different set of data 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'); }
i use config basic (bootstrap) data as:
application.ini
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" ; ___ replaced space, __ point (or set nest separator) resources.view.headlink.shortcut___icon.href = "/favicon.png" resources.view.headlink.shortcut___icon.type = "image/png" ...
at point, maybe have special data. example in:
project1.ini
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, mix in
bootstrap.php
(example *_initheadlink()*):
// $options = app options (basic) // $projectoptions = project options (special) // $assets_url = assets url if ( is_array($headstyle = $options['headstyle']) ) { foreach ( $headstyle $media => $value ) { foreach ( $value $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, value rel foreach ( $headlinks $rel => $value ) { $rel = str_replace(array('___', '__'), array(' ', '.'), $rel); $this->view->headlink()->headlink(array_merge(array('rel' => $rel), (array) $value)); }
then, can override these data controller: setname, set...
i hope helps ;)
Comments
Post a Comment