symfony 2 : Namespace “Acme” does not contain any mapped entities

后端 未结 7 2333
醉酒成梦
醉酒成梦 2021-02-13 04:23

I am following the book and on the page http://symfony.com/doc/current/book/doctrine.html

While following the book I am trying to work on relationship of product and cat

相关标签:
7条回答
  • 2021-02-13 04:41

    In book http://symfony.com/doc/current/book/doctrine.html entity Porduct has been manually created. You wrote code to Product.php. All information about entity fields contains in annotations.
    But entity Category has been created with

    php app/console doctrine:generate:entity --entity="AcmeStoreBundle:Category" --fields="name:string(255)"

    Automatically generated entity Caterory.php doesn't contains annotations. Symfony stored information in "Acme\StoreBundle\Resources\config\doctrine\Category.orm.yml". That's why php app/console doctrine:mapping:info says that you have only 1 mapped entity - Category.

    Solving
    You may generate Product entity with doctrine:generate:entity
    or
    Manually add information about Product entity to "Acme\StoreBundle\Resources\config\doctrine\Category.orm.yml"
    or
    Delete "Acme\StoreBundle\Resources\config\doctrine\Category.orm.yml" and describe Category entity with annotations in Category.php

    0 讨论(0)
  • 2021-02-13 04:42

    Check that the PHP opening and (optional) closing tags

    <?php  
    

    and

    ?>
    

    are correct in your file.

    They are not included when you copy paste from the tutorial at http://symfony.com/doc/current/book/doctrine.html

    I was stuck at the same problem. After looking at this post I started wondering why the syntax highlighting was broken and discovered that the opening and closing tags were missing. The error disappeared when the tags were included.

    0 讨论(0)
  • 2021-02-13 04:48

    The solution:

    Update symfony files:

    composer update
    

    then create entities

    php bin/console doctrine:generate:entities BackendBundle
    
    0 讨论(0)
  • 2021-02-13 04:53

    This error will also come up if your projects (only?) Entity is namespaced incorrectly. If you run the command

    $ php app/console doctrine:generate:entities MyBundle
    

    and it produces the error

    [RuntimeException]
    Bundle "MyBundle" does not contain any mapped entities.

    Check the more specific command....

    $ php app/console doctrine:generate:entities MyBundle:MyEntity
    

    And see if you get the error:

    [RuntimeException]
    The autoloader expected class "MyBundle\Entity\MyEntity" to be defined in file "/path/to/MyBundle/Entity/MyEntity.php". The file was found but the class was not in it, the class name or namespace probably has a typo.

    If so, well then, the error speaks for itself (hopefully) and the namespace/class name needs to be corrected. Hopefully that is helpful to someone.

    0 讨论(0)
  • 2021-02-13 04:55

    With

    doctrine:generate:entity
    

    you'll create new entity.

    And when you add some attributes by hand with

    doctrine:generate:entities AcmeDemoBundle:User
    

    you'll create all accessor (getter and setter) of the entity User of AcmeDemoBundle

    0 讨论(0)
  • 2021-02-13 04:55

    I personally had the error because I was missing the folder/directory "Entity".

    0 讨论(0)
提交回复
热议问题