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 category table and doctrine generate command is giving me following error.
php app/console doctrine:generate:entities Acme
Generating entities for namespace "Acme"
[RuntimeException]
Namespace "Acme" does not contain any mapped entities.
doctrine:generate:entities [--path="..."] [--no-backup] name
Thx
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
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.
The solution:
Update symfony files:
composer update
then create entities
php bin/console doctrine:generate:entities BackendBundle
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
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.
I personally had the error because I was missing the folder/directory "Entity".
One of the two things may be the problem,
make sure you have a use statement at the top, that is
use Acme\StoreBundle\Entity\Product;
It is not included in the example, they only displayed
use Doctrine\Common\Collections\ArrayCollection;
When specifying target entity always specify full namespace if the entities are in different name spaces.
example:
@ORM\OneToMany(targetEntity="Acme\StoreBundle\Entity\Product", mappedBy="category")
instead of:
@ORM\OneToMany(targetEntity="Product", mappedBy="category")
The second one only works if the two entities are in same namespace and that entity has been called by use
statement above the class.