php symfony 2:命名空间“Acme”不包含任何映射实体

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11464819/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 00:35:02  来源:igfitidea点击:

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

phpsymfonydoctrine

提问by Shane Young

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

我正在关注这本书和页面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

谢谢

回答by sensorario

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

您将创建 AcmeDemoBundle 的实体 User 的所有访问器(getter 和 setter)

回答by JTG

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.

[RuntimeException]
捆绑包“MyBundle”不包含任何映射实体。

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.

[RuntimeException]
自动加载器期望在文件“/path/to/MyBundle/Entity/MyEntity.php”中定义类“MyBundle\Entity\MyEntity”。找到了文件但类不在其中,类名或命名空间可能有拼写错误。

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.

如果是这样,那么,错误不言自明(希望如此)并且需要更正命名空间/类名。希望这对某人有帮助。

回答by AZ Angel Azcona

The solution:

解决方案:

Update symfony files:

更新 symfony 文件:

composer update

then create entities

然后创建实体

php bin/console doctrine:generate:entities BackendBundle

回答by marvin_x

Check that the PHP opening and (optional) closing tags

检查 PHP 开始和(可选)结束标记

<?php  

and

?>

are correct in your file.

在您的文件中是正确的。

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

当您从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.

我被困在同样的问题上。看完这篇文章后,我开始想知道为什么语法突出显示被破坏,并发现开始和结束标记丢失了。包含标签后错误消失。

回答by aneth101

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

我个人有错误,因为我缺少文件夹/目录“实体”。

回答by alvlp4

In book http://symfony.com/doc/current/book/doctrine.htmlentity 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

在书中http://symfony.com/doc/current/book/doctrine.html实体产品已被手动创建。您将代码写入 Product.php。关于实体字段的所有信息都包含在 annotations 中
但是实体 Category 已经创建

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

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

Automatically generated entityCaterory.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:infosays that you have only 1 mapped entity - Category.

自动生成的实体Caterory.php不包含 annotations。Symfony 将信息存储在“Acme\StoreBundle\Resources\config\doctrine\Category.orm.yml”中。这就是为什么php app/console doctrine:mapping:info说您只有 1 个映射实体 - 类别。

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

解决
您可以使用doctrine:generate:entity

手动将有关产品实体的信息添加到“Acme\StoreBundle\Resources\config\doctrine\Category.orm.yml”

删除“Acme\StoreBundle\Resources\config\doctrine\Category.orm.yml”来生成产品实体" 并在 Category.php 中用注释描述 Category 实体

回答by mukulu

One of the two things may be the problem,

这两件事之一可能是问题所在,

  1. 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;

  2. 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 usestatement above the class.

  1. 确保顶部有一个 use 语句,即

    use Acme\StoreBundle\Entity\Product;

    它不包含在示例中,它们只显示 use Doctrine\Common\Collections\ArrayCollection;

  2. 如果实体位于不同的命名空间中,则在指定目标实体时始终指定完整的命名空间。例子:

    @ORM\OneToMany(targetEntity="Acme\StoreBundle\Entity\Product", mappedBy="category")

    代替:

    @ORM\OneToMany(targetEntity="Product", mappedBy="category")

    第二个仅在两个实体位于同一命名空间中并且该实体已被use类上方的语句调用时才有效。