Symfony объект таблицы также распознается как репозиторий - PullRequest
1 голос
/ 12 июля 2020

Новое для Symfony и StackOverflow в качестве OP.

Я собираюсь добавить новые mysql объекты таблиц и репозитории на Symfony (4.3.2) и застрял, когда я Попробуй это. Я действительно ценю чью-то помощь.

Я получил ошибку

[2020-07-13 03:25:59] request.CRITICAL: Uncaught PHP Exception RuntimeException: "The "App\Entity\Foo" entity has a repositoryClass set to "App\Repository\Foo", but this is not a valid class. Check your class naming. If this is meant to be a service id, make sure this service exists and is tagged with "doctrine.repository_service"." at /var/www/html/bar_project/vendor/doctrine/doctrine-bundle/Repository/ContainerRepositoryFactory.php line 66 {"exception":"[object] (RuntimeException(code: 0): The \"App\\Entity\\Foo\" entity has a repositoryClass set to \"App\\Repository\\Foo\", but this is not a valid class. Check your class naming. If this is meant to be a service id, make sure this service exists and is tagged with \"doctrine.repository_service\". at /var/www/html/bar_project/vendor/doctrine/doctrine-bundle/Repository/ContainerRepositoryFactory.php:66)"} []

, где Foo в / App / Entity / - это сущность для таблицы foo. и проблема в том, что он пытается сослаться на Foo в App / Repository / как на свой несуществующий репозиторий, но не на FooRepository, который существует. (Обновлен этот абзац после комментария от Jakumi)

(FooController.php)

$repository = $this->getDoctrine()->getRepository(Foo::class);
(Foo.php)

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Table(name="foo")
 * @ORM\Entity(repositoryClass="App\Repository\FooRepository") // *1
 */
class Foo
{
...
(FooRepository.php)

<?php

namespace App\Repository;

use App\Entity\Foo;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Symfony\Bridge\Doctrine\RegistryInterface;

/**
 * @method Foo|null find($id, $lockMode = null, $lockVersion = null)
 * ...
 */
class FooRepository extends ServiceEntityRepository
{
...

Одна вещь, которую я считаю загадочной, заключается в том, что тот же журнал ошибок все еще отображается, даже если я удалю *1. (Я думаю, что у меня работают часы yarn watch и cache clear.)

Дополнительная информация 1

(doctrine.yaml)

doctrine:
    dbal:
        # configure these for your database server
        driver: 'pdo_mysql'
        server_version: '8.0'
        charset: utf8mb4
        default_table_options:
            charset: utf8mb4
            collate: utf8mb4_unicode_ci
        # dbname:
        # host:
        # port:
        # user:
        # password:
        url: '%env(resolve:DATABASE_URL)%'
        options:
          1002: 'SET sql_mode=(SELECT REPLACE(@@sql_mode, "ONLY_FULL_GROUP_BY", ""))'
    orm:
        auto_generate_proxy_classes: true
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true
        metadata_cache_driver: apcu
        result_cache_driver: apcu
        query_cache_driver: apcu
        connection: ~
        mappings:
            App:
                is_bundle: false
                type: annotation
                dir: '%kernel.project_dir%/src/Entity'
                prefix: 'App\Entity'
                alias: App
        dql:
          string_functions:
            group_concat: DoctrineExtensions\Query\Mysql\GroupConcat
            date_format: DoctrineExtensions\Query\Mysql\DateFormat
...