“Class XXX is not a valid entity or mapped super class” after moving the class in the filesystem

前端 未结 12 1139
悲哀的现实
悲哀的现实 2020-12-01 08:51

I had an entity class in Aib\\PlatformBundle\\Entity\\User.php

I had no problems trying to create its form class through

php app/ console doc

相关标签:
12条回答
  • 2020-12-01 09:11

    big thx to Mark Fu and mogoman

    I knew it had to be somewhere in the config.yml... and being able to test it against the

    app/console doctrine:mapping:info
    

    really helped!

    In fact, this command just simply stops at an error... no feedback, but when everything is fine you should be able to see all your entities listed.

    0 讨论(0)
  • 2020-12-01 09:13

    Do check your config.yml file, should be containing something like this:

    # Doctrine Configuration
    doctrine:
        dbal:
            driver:   %database_driver%
            host:     %database_host%
            port:     %database_port%
            dbname:   %database_name%
            user:     %database_user%
            password: %database_password%
            charset:  UTF8
            types:
                json: Sonata\Doctrine\Types\JsonType
    
        orm:
            auto_generate_proxy_classes: %kernel.debug%
            # auto_mapping: true
            entity_managers:
                default:
                    mappings:
                        FOSUserBundle: ~
                        # ApplicationSonataUserBundle: ~
                        YourUserBundle: ~
                        SonataUserBundle: ~
    

    Add your own bundle to the mappings list.

    0 讨论(0)
  • 2020-12-01 09:14

    In my case on my mac I was using src/MainBundle/Resource/Config/Doctrine, of course it worked on Mac but it didn't work on production Ubuntu server. Once renamed Config to config and Doctrine to doctrine, the mapping files were found and it started working.

    0 讨论(0)
  • 2020-12-01 09:17

    In my case, I was too zealous during a refactor and had deleted a doctrine yml file!

    0 讨论(0)
  • 2020-12-01 09:17

    I got rid of the same error message as in your case by using app/console_dev instead of just app/console

    0 讨论(0)
  • 2020-12-01 09:20

    Had this problem yesterday and found this thread. I created the entity with the mapping in a new bundle (e.g. MyFooBundle/Entity/User.php), did all the configuration according to the docs but got the same error from above when trying to load the app.

    In the end I realized that I wasn't loading MyFooBundle in AppKernel:

    new My\FooBundle\MyFooBundle()
    

    A great way to debug this is to run this command:

    app/console doctrine:mapping:info
    
    0 讨论(0)
提交回复
热议问题