configuration - How to access configs from autoloaded config files in a layout / view script in Zend Framework 2? -


i / have manage settings in zf1 style , provide view infomation current environment.

/config/application.config.php

return array(     ...     'module_listener_options' => array(         ...         'config_glob_paths' => array('config/autoload/{,*.}{global,local}.php')     ) ); 

/config/autoload/env.local.php

return array(     // allowed values: development, staging, live     'environment' => 'development' ); 

in common view script can on controller, since controllers have access service manager , configs need:

class mycontroller extends abstractactioncontroller {      public function myaction() {         return new viewmodel(array(             'currentenvironment' => $this->getservicelocator()->get('config')['environment'],         ));     }  } 

is possible configs in common view directly?

how can access configs in layout view script (/module/application/view/layout/layout.phtml)?

(my implementation/interpretation of) crisp's suggestion:

config view helper

<?php namespace mynamespace\view\helper;  use zend\view\helper\abstracthelper; use zend\view\helperpluginmanager servicemanager;  class config extends abstracthelper {      protected $servicemanager;      public function __construct(servicemanager $servicemanager) {         $this->servicemanager = $servicemanager;     }      public function __invoke() {         $config = $this->servicemanager->getservicelocator()->get('config');         return $config;     }  } 

application module class

public function getviewhelperconfig() {     return array(         'factories' => array(             'config' => function($servicemanager) {                 $helper = new \mynamespace\view\helper\config($servicemanager);                 return $helper;             },         )     ); } 

layout view script

// whatever want $this->config()['environment'], e.g. <?php if ($this->config()['environment'] == 'live') {     echo $this->partial('partials/partial-foo.phtml');; } ?> 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -