学说“实体”不是有效的实体或映射的超类

vuk*_*icf 3 php doctrine symfony symfony6

在我的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'
                ]
            ]
        ]
    ]);
};
Run Code Online (Sandbox Code Playgroud)

我的实体类定义如下

namespace App\Entity;

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

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

...
Run Code Online (Sandbox Code Playgroud)

getRepository我尝试通过这样的调用来访问它

$entityRepository = $entityManager->getRepository(Entity::class);
Run Code Online (Sandbox Code Playgroud)

但这失败了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);
    }
}
Run Code Online (Sandbox Code Playgroud)

vuk*_*icf 11

我发现一个问题。我是个假人..

我必须改变

'type' => 'annotation'
Run Code Online (Sandbox Code Playgroud)

'type' => 'attribute'
Run Code Online (Sandbox Code Playgroud)

因为我使用的是 php8 语法。对不起各位!