簡體   English   中英

Doctrine “實體”不是有效實體或映射的超級 class

[英]Doctrine "Entity" is not a valid entity or mapped super class

在我的doctrine.php我有以下配置

<?php

// See https://symfony.com/doc/current/reference/configuration/framework.html

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

return static function (ContainerConfigurator $container) {
    $container->extension('doctrine', [
        'dbal' => [
            'url' => '%env(DATABASE_URL)%',
        ],
        'orm' => [
            'auto_generate_proxy_classes' => true,
            'auto_mapping' => true,
            'mappings' => [
                'default' => [
                    'is_bundle' => false,
                    'type' => 'annotation',
                    'dir' => '%kernel.project_dir%/src/Entity',
                    'prefix' => 'App\Entity',
                    'alias' => 'App'
                ]
            ]
        ]
    ]);
};

而我的實體 class 定義如下

namespace App\Entity;

use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Table;

#[Entity(repositoryClass: EntityRepository::class)]
#[Table(name: 'entity')]
class Entity

...

我嘗試通過像這樣調用getRepository來訪問它

$entityRepository = $entityManager->getRepository(Entity::class);

但這is not a valid entity or mapped super class

附言

如有必要,這是我的EntityRepository.php

<?php

namespace App\Repository;

use App\Entity\Entity;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

class EntityRepository extends ServiceEntityRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, Entity::class);
    }
}

我發現了一個問題。 我是個假人。。

我不得不改變

'type' => 'annotation'

'type' => 'attribute'

因為我使用的是 php8 語法。 對不起小伙子們!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM