php - ZfcTwig is not loading config and fails in bootstrap -
hi relatively new zf2 might simple mistake making.
problem
when loading zfctwig
module exception
fatal error: uncaught exception 'zend\servicemanager\exception\servicenotfoundexception' message 'zend\servicemanager\servicemanager::get unable fetch or create instance twig_environment' in /www/zendframework2/library/zend/servicemanager/servicemanager.php on line 555
this exception thrown in onbootstrap
function of zfctwig\module.php
:
<?php class module implements bootstraplistenerinterface, configproviderinterface { public function onbootstrap(eventinterface $e) { /** @var \zend\mvc\mvcevent $e*/ $application = $e->getapplication(); $servicemanager = $application->getservicemanager(); $environment = $servicemanager->get('twig_environment'); // throws exception //... } public function getconfig(){ return [/*...*/]; } // never called }
what don't why bootstrap called before configuration loaded. 'twig_environment'
service configured in config of zfctwig module, config has not been loaded, when onbootstrap called.
setup
zf2 loader via zf2_path
environment variable. not using composer autoloader.
in application.config.php
set additional modules path '/global/vendor'
sytem wide repository of reusable modules. not using project local vendor folder.
from '/global/vendor/zfctwig'
loading module zfctwig
(link) twig template engine support in zf2.
since relies on twig library put twig lib '/global/vendor/twig'
to enable autoloading zfctwig module , twig library classes changed module.php of zfctwig implementing autoloaderproviderinterface
, adding configs both twig , zfctwig.
<?php class module implements bootstraplistenerinterface, autoloaderproviderinterface, configproviderinterface { /** * autoloading twig library , modules classes * @return array */ public function getautoloaderconfig() { $pathtotwiglib = dirname(dirname(dirname(__dir__))) . '/twig/twig/lib/twig'; return array( 'zend\loader\standardautoloader' => array( 'namespaces' => array( __namespace__ => __dir__, ), 'prefixes' => array( 'twig_' => $pathtotwiglib, ), ), ); }
in application.config.php
loading modules ['application','twig','zfctwig']
auto loading twig working (at least can instantiate twig_environment
in bootstrap of zfctwig , other controllers using new
).
had config cache enabled
the problem wondering myself. config needs loaded before bootstrapping done. zf2 does, unless, me, have config cache enabled.
<?php // config/applicaiton.config.php return array( 'module_listener_options' => array( // prevents call getconfig on modules // implement configproviderinterface // default: false 'config_cache_enabled' => true, ) );
Comments
Post a Comment