1

Доброе время суток, подскажите что нужно поправить в Symfony 4 что бы doctrine работала с репозиторием? Сейчас при попытке зайти на страницу выдает ошибку:

The class 'App\Repository\PageModulesRepository' was not found in the chain configured namespaces App\Entity

Собственно сам репозиторий:

namespace App\Repository;

use App\Entity\PageModules;
use Doctrine\ORM\EntityRepository;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Symfony\Bridge\Doctrine\RegistryInterface;

class PageModulesRepository extends EntityRepository
{

    public function __construct()
    {

    }
}

Собственно сам контроллер

namespace App\Controller;
use App\Repository\PageModulesRepository;
use Doctrine\Common\Annotations\AnnotationReader;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;
class ApiController extends Controller
{
    /**
     * @Route("/api", name="api")
     */
    public function index()
    {

        $do = $this->getDoctrine();
        $treeR = $do->getRepository(PageModulesRepository::class);

        return $this->json([
            'message' => 'Welcome to your new controller!',
            'path' => 'src/Controller/ApiController.php',
        ]);
    }
}

Подозреваю что проблема может быть где то тут:

Конфиг доктрины:

parameters:
    # Adds a fallback DATABASE_URL if the env var is not set.
    # This allows you to run cache:warmup even if your
    # environment variables are not available yet.
    # You should not need to change this value.
    env(DATABASE_URL): ''

doctrine:
    dbal:
        # configure these for your database server
        driver: 'pdo_mysql'
        server_version: '5.7'
        charset: utf8mb4
        default_table_options:
            charset: utf8mb4
            collate: utf8mb4_unicode_ci

        url: '%env(resolve:DATABASE_URL)%'
    orm:
        auto_generate_proxy_classes: '%kernel.debug%'
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true
        mappings:
            App:
                is_bundle: false
                type: annotation
                dir: '%kernel.project_dir%/src/Entity'
                prefix: 'App\Entity'
                alias: App

Я пробовал убирать секцию mappings: в конфиге Тогда он просто говорит

The class 'App\Repository\PageModulesRepository' was not found in the chain configured namespaces

Подскажите как починить?

1 ответ 1

7

Репозиторий ищется по имени entity, а не по классу репозитория:

$do->getRepository(PageModules::class);
0

Ваш ответ

Нажимая на кнопку «Отправить ответ», вы соглашаетесь с нашими условиями использования и подтверждаете, что прочитали и поняли наши политику конфиденциальности и нормы поведения.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.