Note that there are some explanatory texts on larger screens.

plurals
  1. POZF2 Zend framework not calling global.php for Album tutorial application
    text
    copied!<p>I have been getting an error: Zend\ServiceManager\Exception\ServiceNotCreatedException: An exception was raised while creating "Zend\Db\Adapter\Adapter"; no instance returned.</p> <p>Tracing this down, I found that Zend\Db\Adapter\Adapter is presented in global.php. But, global.php is never being called or at least hasn't been called before module.php getserviceconfig() where the error is tripping. Both testconfig.php.dist and application.config.php present global.php to the listener defintion. But, global.php never executes.</p> <p>Can someone please tell me why? Definitions follow.</p> <p>global.php</p> <pre><code>&lt;?php echo PHP_EOL . "Global.php executed." . PHP_EOL; return array( 'db' =&gt; array( 'driver' =&gt; 'Pdo', 'dsn' =&gt; 'mysql:dbname=zf2tutorial;host=album.techmate.com', 'driver_options' =&gt; array( PDO::MYSQL_ATTR_INIT_COMMAND =&gt; 'SET NAMES \'UTF8\'' ), ), 'service_manager' =&gt; array( 'factories' =&gt; array( 'Zend\Db\Adapter\Adapter' =&gt; 'Zend\Db\Adapter\AdapterServiceFactory', ), ), ); ?&gt; </code></pre> <p>testconfig.php.dist</p> <pre><code>&lt;?php echo PHP_EOL . "TestConfig.php.dist executed." . PHP_EOL; return array( 'modules' =&gt; array( 'Album', // &lt;-- Add this line ), 'module_listener_options' =&gt; array( 'config_glob_paths' =&gt; array( 'config/autoload/{,*.}{global,local}.php', ), 'module_paths' =&gt; array( './module', './vendor', ), ), ); ?&gt; </code></pre> <p>application.config.php</p> <pre><code>&lt;?php echo PHP_EOL . "Application.config.php executed." . PHP_EOL; return array( 'modules' =&gt; array( 'Album', // &lt;-- Add this line ), 'module_listener_options' =&gt; array( 'config_glob_paths' =&gt; array( 'config/autoload/{,*.}{global,local}.php', ), 'module_paths' =&gt; array( './module', './vendor', ), ), ); ?&gt; </code></pre> <p>module.php just for completeness...</p> <pre><code>&lt;?php namespace Album; use Album\Model\Album; use Album\Model\AlbumTable; use Zend\Db\ResultSet\ResultSet; use Zend\Db\TableGateway\TableGateway; use Zend\ModuleManager\Feature\ServiceProviderInterface; use Zend\Db\Adapter\Adapter as DbAdapter; class Module implements ServiceProviderInterface { public function getAutoloaderConfig() { return array( 'Zend\Loader\ClassMapAutoloader' =&gt; array( __DIR__ . '/autoload_classmap.php', ), 'Zend\Loader\StandardAutoloader' =&gt; array( 'namespaces' =&gt; array( __NAMESPACE__ =&gt; __DIR__ . '/src/' . __NAMESPACE__, ), ), ); } public function getConfig() { return include __DIR__ . '/config/module.config.php'; } // Add this method: public function getServiceConfig() { return array( 'factories' =&gt; array( /* 'Zend\db\Adapter\Adapter' =&gt; function($sm) { echo PHP_EOL . "SM db-adapter executed." . PHP_EOL; $config = $sm-&gt;get('config'); $config = $config['db']; $dbAdapter = new DbAdapter($config); return $dbAdapter; },*/ 'Album\Model\AlbumTable' =&gt; function($sm) { echo PHP_EOL . "SM AlbumTable executed." . PHP_EOL; $tableGateway = $sm-&gt;get('AlbumTableGateway'); $table = new AlbumTable($tableGateway); return $table; }, 'AlbumTableGateway' =&gt; function ($sm) { echo PHP_EOL . "SM AlbumTableGateway executed." . PHP_EOL; $dbAdapter = $sm-&gt;get('Zend\Db\Adapter\Adapter'); $resultSetPrototype = new ResultSet(); $resultSetPrototype-&gt;setArrayObjectPrototype(new Album()); return new TableGateway('album', $dbAdapter, null, $resultSetPrototype); }, ), ); } } ?&gt; </code></pre> <p>And the error...</p> <pre><code>TestConfig.php.dist executed. Module.config.php executed. PHPUnit 3.7.10 by Sebastian Bergmann. Configuration read from D:\PHP\zf2-tutorial\module\Album\test\phpunit.xml.dist ......E SM AlbumTable executed. SM AlbumTableGateway executed. Time: 0 seconds, Memory: 8.50Mb There was 1 error: 1) AlbumTest\Model\AlbumTableTest::testGetAlbumTableReturnsAnInstanceOfAlbumTable Zend\ServiceManager\Exception\ServiceNotFoundException: Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for Zend\Db\Adapter\Adapter D:\PHP\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php:450 D:\PHP\zf2-tutorial\module\Album\Module.php:50 D:\PHP\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php:726 D:\PHP\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php:843 D:\PHP\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php:487 D:\PHP\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php:442 D:\PHP\zf2-tutorial\module\Album\Module.php:44 D:\PHP\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php:726 D:\PHP\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php:843 D:\PHP\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php:487 D:\PHP\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php:442 D:\PHP\zf2-tutorial\module\Album\src\Album\Controller\AlbumController.php:33 D:\PHP\zf2-tutorial\module\Album\test\AlbumTest\Model\AlbumTableTest.php:149 FAILURES! Tests: 7, Assertions: 9, Errors: 1. </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload