Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

symfony 2 : Namespace "Acme" does not contain any mapped entities

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

like image 960
Shane Young Avatar asked Jul 13 '12 05:07

Shane Young


4 Answers

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

like image 165
sensorario Avatar answered Nov 07 '22 05:11

sensorario


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.

like image 39
JTG Avatar answered Nov 07 '22 07:11

JTG


The solution:

Update symfony files:

composer update

then create entities

php bin/console doctrine:generate:entities BackendBundle
like image 4
AZ Angel Azcona Avatar answered Nov 07 '22 07:11

AZ Angel Azcona


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.

like image 3
marvin_x Avatar answered Nov 07 '22 07:11

marvin_x