php - Where should be stored the environment dependent configs in a Zend Framework 2 application? -
a zf2 application contains/nneds lot of different config files: /config/application.config.php
, /config/autoload/global.php
, /config/autoload/local.php
, /module/***/config/module.config.php
.
now i've written module, covers caching functionality application, , need different values livetime of items in local/dev , live environment. able switch cache type dependent on environment.
where should such stuff sored? in /config/autoload/global.php
, /config/autoload/local.php
? if yes: should first retrieved these files in module
class (e.g. in onbootstrap()
method) or used directly, it's needed?
(it great, if show primitive example saving , getting such config data.)
the solution, i'm using is:
/config/autoload/global.php
and/or /config/autoload/local.php
return array( // db credentials 'db' => array( 'username' => ..., 'password' => ..., 'dbname' => ..., 'host' => ..., ), 'cache_ttl' => 'global/local value cache live time', );
cache module
class
class module { private $moduleconfig; public function onbootstrap(mvcevent $mvcevent) { $application = $mvcevent->getparam('application'); $this->moduleconfig = $application->getconfig(); } ... public function getserviceconfig() { try { return array ( 'factories' => array( ... 'zend\cache\adapter\memcachedoptions' => function ($servicemanager) { return new memcachedoptions(array( 'ttl' => $this->moduleconfig['cache_ttl'], ... )); }, ... ) ); } ... } }
it works fine, i'm pretty sure, it's not best practice / recomended way.
Comments
Post a Comment