未找到 Doctrine 注释阅读器类

奥博菲尼

我开始在 silex 中使用带有来自文档的简单注释的学说@Entity并且它起作用了。现在我看到 symfony 使用 importuse Doctrine\ORM\Mapping as ORM;@ORM\Entity. 但是当我添加这个时,学说会抛出一个错误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;

我的配置没有额外的选项

$config = Setup::createAnnotationMetadataConfiguration([
    __DIR__.'/../src/Entity/'
]);


$app['db.em'] = EntityManager::create($app['db'], $config);
卢多

您正在使用SimpleAnnotationReaderwhich 无法从非直接导入的命名空间加载注释。您可以通过false为元数据配置传递第 5 个参数来轻松切换

public static function createAnnotationMetadataConfiguration(array $paths, $isDevMode = false, $proxyDir = null, Cache $cache = null, $useSimpleAnnotationReader = true)

所以在你的情况下:

$config = Setup::createAnnotationMetadataConfiguration(
    [__DIR__.'/../src/Entity/'],
    false,
    null,
    null,
    false
]);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章