I must use \\Doctrine\\Common\\Annotations\\AnnotationRegistry::registerFile
to access the annotation registry in entity files.
This part is required to use
Thank you Samuel Herzog. It works perfect for me. I was generating the Vendors using composer.json. So When I added my autoload.php i just needed to add these sentences...
<?php
// autoload.php generated by Composer
use Doctrine\Common\Annotations\AnnotationRegistry;
require_once dirname( __DIR__ ).'/vendor/composer/autoload_real.php';
$loader = ComposerAutoloaderInit0cf45a42473ebbcd4516460f93747271::getLoader();
AnnotationRegistry::registerFile( dirname( __DIR__ ).'/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php' );
return $loader;
Just like that.
It seems your AnnotationRegistry
isn't set up.
Add the following to your script:
use Doctrine\Common\Annotations\AnnotationRegistry;
AnnotationRegistry::registerFile("/path/to/doctrine/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php");
see Doctrine manual on Annotations for the detailed explanation.
In short: to read the annotations PSR-0 and spl autoloading can't do the job, you have to use their solution.