I want to built Doctrine 2 into an Apigility Zend Framework 2 application.
Following Marco Pivetta's Doctrine ORM ZF2 Tutorial, I installed not only Doctrine, but also the Zend Developer Tools, like in the tutorial shown:
$ composer require doctrine/doctrine-orm-module
$ composer require zendframework/zend-developer-tools:dev-master
$ cp vendor/zendframework/zend-developer-tools/config/zenddevelopertools.local.php.dist config/autoload/zdt.local.php
// config/application.config.php
return array(
'modules' => array(
'Application',
...
'ZendDeveloperTools', // <-- added
'DoctrineModule', // <-- added
'DoctrineORMModule', // <-- added
),
// [...]
);
Now when I open the Apigility admin page, I get errors:
Fatal error: Uncaught exception 'Zend\Db\Adapter\Exception\InvalidArgumentException' with message 'createDriver expects a "driver" key to be present inside the parameters' in /var/www/myproject/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php on line 909
Zend\Db\Adapter\Exception\InvalidArgumentException: createDriver expects a "driver" key to be present inside the parameters in /var/www/myproject/vendor/zendframework/zendframework/library/Zend/Db/Adapter/Adapter.php on line 262
Zend\ServiceManager\Exception\ServiceNotCreatedException: An exception was raised while creating "Zend\Db\Adapter\Adapter"; no instance returned in /var/www/myproject/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php on line 909
Zend\ServiceManager\Exception\ServiceNotCreatedException: An exception was raised while creating "ZendDeveloperTools\DbCollector"; no instance returned in /var/www/myproject/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php on line 909
The errors occur, when the zenddevelopertools.toolbar.enabled
is set to true
.
Here is the configuration in the /config/autoload/global.php
:
return array(
'db' => array(
'adapters' => array(
'DB\\Customers' => array(),
'DB\\myproject_v1' => array(),
'DB\\myproject_v2' => array(),
),
),
'service_manager' => array(
'factories' => array(
'Zend\\Db\\Adapter\\Adapter' => 'Zend\\Db\\Adapter\\AdapterServiceFactory',
),
),
'zf-mvc-auth' => array(
...
),
);
and the /config/autoload/local.php
looks like follows:
return array(
'db' => array(
'adapters' => array(
'DB\\Customers' => array(
'driver' => 'Pdo_Sqlite',
'database' => 'data/sqlite.db',
),
'DB\\myproject_v1' => array(
'driver' => 'Pdo_Mysql',
'database' => 'myproject_v1',
'username' => 'root',
'password' => 'pwd',
'hostname' => 'localhost',
'driver_options' => array(
1002 => 'SET NAMES \'UTF8\'',
),
),
'DB\\myproject_v2' => array(
'driver' => 'Pdo_Mysql',
'database' => 'myproject_v2',
'username' => 'root',
'password' => 'pwd',
'hostname' => 'localhost',
'driver_options' => array(
1002 => 'SET NAMES \'UTF8\'',
),
),
),
),
'zf-mvc-auth' => array(
...
),
);
I guess, the Zend Developer Tools cannot find an appropriate DB adapter.
Why are these errors occuring and how to ix them?
Additional info:
The db.service_manager.factories.Zend\\Db\\Adapter\\Adapter
configuration in my global.php
is actually needless, since I use custom DB adapters instead of the default one created by Zend\Db\Adapter\AdapterServiceFactory
. Anyway the Zend Developer Tools seem to try to use it. So, when I copy the DB settings directly to db
return array(
'db' => array(
'adapters' => array(
...
'driver' => 'Pdo_Mysql',
'username' => 'root',
'password' => 'pwd',
'hostname' => 'localhost',
'database' => 'myproject_v1',
),
),
...
);
I get different errors:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[28000] [1045] Access denied for user 'username'@'localhost' (using password: YES)' in /var/www/myproject/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php on line 1070
PDOException: SQLSTATE[28000] [1045] Access denied for user 'username'@'localhost' (using password: YES) in /var/www/myproject/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php on line 43