Reputation: 2008
I started to use doctrine in silex with simple annotations from docs @Entity
and it worked. And now I see that symfony uses import use Doctrine\ORM\Mapping as ORM;
and @ORM\Entity
. But when I add this, doctrine throws an error
Class "App\Entity\Author" is not a valid entity or mapped super class.
namespace App\Entity;
use App\Helpers\Jsonable;
use App\Helpers\MassAssignable;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\AuthorRepository")
* @ORM\Table(name="authors")
*/
class Author
{
use MassAssignable;
use Jsonable;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @var int
*/
protected $id;
/**
* @ORM\Column(type="string")
* @var string
*/
protected $name;
My config has no additional oprions
$config = Setup::createAnnotationMetadataConfiguration([
__DIR__.'/../src/Entity/'
]);
$app['db.em'] = EntityManager::create($app['db'], $config);
Upvotes: 0
Views: 943
Reputation: 512
You are using SimpleAnnotationReader
which cannot load annotations from not directly imported namespaces. You can switch this easily by passing false
as 5th param for metadata config.
public static function createAnnotationMetadataConfiguration(array $paths, $isDevMode = false, $proxyDir = null, Cache $cache = null, $useSimpleAnnotationReader = true)
So in your case:
$config = Setup::createAnnotationMetadataConfiguration(
[__DIR__.'/../src/Entity/'],
false,
null,
null,
false
]);
Upvotes: 1