Zend Framework 2 Quick Start with Doctrine

I am trying to get ZF2 Quick Start to work with Doctrine. I thought I configured it correctly, but I get the following error. Has anyone seen this?

File: / Users / jhicks / workspace / zf 2-example / vendor / doctrine / common / lib / Doctrine / Common / Persistence / Mapping / MappingException.php: 38 Message: Class 'Album \ Entity \ Album' was not found in the chain names ZpcUser \ Entity, \ Entity, ZfcUserDoctrineORM \ Entity

Here is my Doctrine configuration:

return array( 'doctrine' => array( 'driver' => array( __NAMESPACE__ . '_driver' => array( 'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver', 'cache' => 'array', 'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Entity') ), 'orm_default' => array( 'drivers' => array( __NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver' ) ) ), 'connection' => array( 'orm_default' => array( 'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver', 'params' => array( 'host' => 'localhost', 'port' => '3306', 'dbname' => 'zf2example', 'user' => 'user', 'password' => 'password' ), ) ) ), ); 
+4
source share
1 answer

If you look closely at the list of object namespaces in the exception message ...

 ZfcUser\Entity, \Entity, ZfcUserDoctrineORM\Entity -------------------^ 

You will notice that one of them is just \Entity . This is because you configured the namespace of the objects in the PHP configuration file somewhere ( config/autoload .: either the file in config/autoload , or your config/module.config.php ), and by default these files do not have a namespace Try adding one of them to the top of the configuration file:

 <?php namespace Album; 

In my local tests, this fixed the problem.

+9
source

Source: https://habr.com/ru/post/1441964/


All Articles