Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend Framework 2 Quick Start with Doctrine

I'm trying to get the ZF2 Quick Start to work with Doctrine. I thought I had it set up correctly but I'm getting the following error. Has anyone seen it?

File: /Users/jhicks/workspace/zf2-example/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/MappingException.php:38 Message: The class 'Album\Entity\Album' was not found in the chain configured namespaces ZfcUser\Entity, \Entity, ZfcUserDoctrineORM\Entity

Here is my Doctrine config:

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'
                ),  
            )
        )
    ),
);
like image 420
Jeremy Hicks Avatar asked Oct 25 '12 04:10

Jeremy Hicks


1 Answers

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

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

You will notice that one of them is just \Entity. This is due to the fact that you've configured your entity namespace in a PHP configuration file somewhere (ie: either a file in config/autoload or your module's config/module.config.php file), and by default those files don't have a namespace. Try adding one to the top of the configuration file:

<?php
namespace Album;

In my local tests this fixed the issue.

like image 86
Adam Lundrigan Avatar answered Oct 04 '22 18:10

Adam Lundrigan