I am working on a CodeIgniter project in which I use Doctrine2 and the Symfony2 Validator component.
All my Doctrine2 objects use Doctrine\ORM\Mapping , and the object manager recognizes them. My annotation of an object is as follows:
/** * @Entity(repositoryClass = "UserRepository") * @Table(name = "user") * @HasLifecycleCallbacks() */
At this point, I can save objects without any problems. The first problem occurs when I try to use the Symfony2 Validator component. When I try to validate a User object, I get this error:
[Semantic error] The @Entity annotations in the Entity \ User class were never imported. Did you forget to add the expression "use" for this annotation?
The only "fix" for this problem is through use Doctrine\Mapping\Entity , but I have to do this for every annotation used by my entity (Table, Column, ManyToOne, etc.). I'm trying to understand why I need to explicitly use each annotation class instead of being automatically recognized (shouldn't use Doctrine\ORM\Mapping give me access to all classes in this namespace?).
So, I tried use Doctrine\ORM\Mapping as ORM and preceded all my annotations with ORM\ . Example: @ORM\Entity() . Symfony2 validator stops complaining, but now Doctrine2 complains that Class Entity\User is not a valid entity or mapped super class. I have no idea why this method works for Validator, but not Doctrine2. If I run the console command doctrine:orm:info , my User object is not recognized.
Since this is a CodeIgniter application, I automatically download the Symfony2 and Doctrine2 libraries. My startup code is as follows:
# Symfony2 ClassLoader component require_once __DIR__ . '/application/libraries/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php'; $loader = new \Symfony\Component\ClassLoader\UniversalClassLoader(); $loader->register(); $loader->registerNamespace('Symfony', __DIR__ . '/application/libraries/symfony/src'); $loader->registerNamespace('Doctrine', __DIR__ . '/application/libraries/doctrine/lib');
I donβt care if I should predict everything with ORM\ or not, I just want to find a solution that Symfony2 Validator and Doctrine2 will work with. Any ideas?