The class was not found in the chain configured namespaces

ε祈祈猫儿з 提交于 2021-01-29 12:51:44

问题


Hello, i need to explain what i'm was doing at first:

  • I was on a project and for some reason I ended up having to use two databases instead of just one. so i do what it was needed to do, i change my doctrine.yaml settings with what is explain in the symfony doc and in that moment the error appeared

An SQL error that says that it was no column found for X request on X table

  • (the error is SQLSTATE[42S02], but it's not important)

(in parallel of that error i need to say that the "--em" shit didn't work for me when i do php bin/console doctrine:migrations:diff/migrate --em=default or customer so i does indeed php bin/console doctrine:schema:update --force --em=default or customer and i don't know why ! so if you have something to say here i'll take it too.)

Anyway i go back to what i was explaining, This sql error appear because of my controller, they working with default Repository implementation (MyClassNameRepository $myClasNameReposiotry for an exemple) that was normaly implement the default EntityManager but it doesn't and that throw this error.

At this point i though that i had an error in some files in symfony because of a shit i probably does. I don't have the time for replacing all the repository implementation, soo i create a new project with the doctrine config that is needed for working with two database according to the symfony doc. Is the same as the One in my project :

doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                # configure these for your database server
                url: '%env(resolve:DATABASE_URL)%'
                driver: 'pdo_mysql'
                server_version: '5.7'
                charset: utf8mb4
            customer:
                # configure these for your database server
                url: '%env(resolve:DATABASE_CUSTOMER_URL)%'
                driver: 'pdo_mysql'
                server_version: '5.7'
                charset: utf8mb4
    orm:
        entity_managers:
            default:
                connection: default
                mappings:
                    Main:
                        is_bundle: false
                        type: annotation
                        dir: '%kernel.project_dir%/src/Entity'
                        prefix: 'App\Entity'
                        alias: Main
            customer:
                connection: customer
                mappings:
                    Customer:
                        is_bundle: false
                        type: annotation
                        dir: '%kernel.project_dir%/src/Entity/Customer'
                        prefix: 'App\Entity\Customer'
                        alias: Customer

That is the same config than the one in symfony doc except for the Main dir. i created my entities, one in each database and i does a crud on them.

The Hierarchy files:

src/
-----Entity/
     ----Product
     ----Customer/
            -ProductCustomer
-----Repository/
     ----ProductRepository
     ----Customer/
         -----ProductCustomerRepository
And same for the form

And with this testApplication i saw a new error, for the customer part i had the same sql error, because the column was searched in the wrong bdd, after changing the code for :

this

    /**
     * @Route("/", name="customer_produit_customer_index", methods={"GET"})
     */
    public function index(ProductCustomerRepository $productCustomerRepository): Response
    {
        return $this->render('customer/produit_customer/index.html.twig', [
            'produit_customers' => $productCustomerRepository->findAll(),
        ]);
    }

to this

    /**
     * @Route("/", name="customer_produit_customer_index", methods={"GET"})
     */
    public function index(): Response
    {
        $productCustomers = $this->getDoctrine()
            ->getRepository(ProduitCustomerRepository::class, "customer")
            ->findAll()
        ;
        return $this->render('customer/produit_customer/index.html.twig', [
            'produit_customers' => $productCustomers,
        ]);
    }

The error has changed, as I expected and know i have :

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

No matter how much I search the internet, I can't find anything that really solves my mistakes. Now I'm tired of looking, especially since I don't understand these errors because it's not the first time I've set up an application connected to two databases, but it's the first time that I have these errors.

So please help me =D.

来源:https://stackoverflow.com/questions/64594642/the-class-was-not-found-in-the-chain-configured-namespaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!