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

前端 未结 12 1140
悲哀的现实
悲哀的现实 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:20

    I resolved the same exception by deleting a conflicting autogenerated orm.php file in the bundle's Resources/config/doctrine folder; according to the documentation: "A bundle can accept only one metadata definition format. For example, it's not possible to mix YAML metadata definitions with annotated PHP entity class definitions."

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

    In my case the problem was solved by changing my servers cache from eAccelerator to APC. Apparently eAccelerator strips all the comments from files which breaks your annotations.

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

    I resolved this issue by setting $useSimpleAnnotationReader=false when creating the MetaDataConfiguration.

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

    Very high possibility that you have PHP 5.3.16 (Symfony 2.x will not work with it). Anyway you should load check page on http://you.site.name/config.php If you had project not worked on hosting server, next lines must be removed in "config.php":

    if (!in_array(@$_SERVER['REMOTE_ADDR'], array(
        '127.0.0.1',
        '::1',
    ))) {
        header('HTTP/1.0 403 Forbidden');
        exit('This script is only accessible from localhost.');
    }
    

    Goodluck!

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

    I solved this by passing false as the second parameter to Doctrine\ORM\Configuration::newDefaultAnnotationDriver.

    It took me a while of digging through Google and source code.

    My case was sort of special since I was using a mapping pointing to another directory unrelated to the Symfony installation as I also had to use legacy code.

    I had refactored legacy entities and they stopped working. They used to use @Annotation instead of @ORM\Annotation, so after refactoring it simply failed to read the metadata. By not using a simple annotation reader, everything seems to be okayish.

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

    Had this problem - don't forget the annotation * @ORM\Entity like below:

    /**
     * Powma\ServiceBundle\Entity\User
     *
     * @ORM\Entity
     * @ORM\Table(name="users")
     */
    
    0 讨论(0)
提交回复
热议问题