未捕获PHP异常Doctrine\ORM\ORMException:“未知实体名称空间别名”AppBundle'。 [英] Uncaught PHP Exception Doctrine\ORM\ORMException: "Unknown Entity namespace alias 'AppBundle'."
问题描述
我刚开始我的第一个项目与作曲家,并想要设置数据库和它的类。但我被卡住了我在prod.log中收到上面的错误
I just started my first project with composer and wanted to set up the database and the classes for it. However I'm stuck. I'm getting the above error in the prod.log
我在这里遵循本教程: http://symfony.com/doc/current/book/doctrine.html
I followed this tutorial here: http://symfony.com/doc/current/book/doctrine.html
我创建数据库
php bin / console doctrine:database:create
然后想创建一个实体
php bin / console doctrine:generate:entity
当被问到实体快捷方式名称
我输入 AppBundle:Product
,然后创建数据库字段等。
and then created the database fields etc.
我收到这条消息
实体生成
Entity generation
生成实体类src / AppBundle / Entity / Product.php:OK!
生成存储库类src / AppBundle / Repository / ProductRepository.php:OK!
Generating entity class src/AppBundle/Entity/Product.php: OK!
Generating repository class src/AppBundle/Repository/ProductRepository.php: OK!
一切都OK!现在上班了:)
Everything is OK! Now get to work :).
所以这听起来像一切正常,对吧?
So this sounds like everything worked, right?
ProductController
我使用这个
$products = $this->getDoctrine()
->getRepository('AppBundle:Product')
->findAll();
我收到错误
[2016-02-15 18:56:14] request.CRITICAL: Uncaught PHP Exception Doctrine\ORM\ORMException: "Unknown Entity namespace alias 'AppBundle'." at /home/vagrant/work/homestead/test/vendor/doctrine/orm/lib/Doctrine/ORM/ORMException.php line 271 {"exception":"[object] (Doctrine\\ORM\\ORMException(code: 0): Unknown Entity namespace alias 'AppBundle'. at /home/vagrant/work/homestead/test/vendor/doctrine/orm/lib/Doctrine/ORM/ORMException.php:271)"} []
我也尝试过
->getRepository('AppBundle\Entity\Product')
但这里我收到消息
[2016-02-15 19:01:39] request.CRITICAL: Uncaught PHP Exception Doctrine\Common\Persistence\Mapping\MappingException: "The class 'AppBundle\Entity\Product' was not found in the chain configured namespaces " at /home/vagrant/work/homestead/test/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/MappingException.php line 37 {"exception":"[object] (Doctrine\\Common\\Persistence\\Mapping\\MappingException(code: 0): The class 'AppBundle\\Entity\\Product' was not found in the chain configured namespaces at /home/vagrant/work/homestead/test/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/MappingException.php:37)"} []
我如何实际得到这个工作/我刚从项目开始。教义创造了课程。我有这样的
How do I actually get this to work/ I just started with the project. Doctrine created the classes though. I have it like this
/src
/src/AppBundle/
/src/AppBundle/Entity
Product.php
/src/AppBundle/Repository
ProductRepository.php
此外,在Product.php中,这是在注释的注释中(如果有帮助的话)
Also, in the Product.php this is in the comments of the annotations (if it helps)
* @ORM\Entity(repositoryClass="AppBundle\Repository\ProductRepository")
此外,尝试此命令 php bin / console doctrine:generate:entities AppBundle
重新创建我没有错误消息的实体。
Also, when trying this command php bin/console doctrine:generate:entities AppBundle
to recreate the entities I'm getting no error message.
我正在获得
Generating entities for bundle "AppBundle"
> backing up Product.php to Product.php~
> generating AppBundle\Entity\Product
推荐答案
解决方案是删除缓存文件,因此如果您正在生产模式下工作,则需要这样做。在调试模式下,这是自动完成的。为了确保这样做,手动将prod文件夹放在var下,如果你在3.x,在应用程序下的2.x中。
The solution is delete the cache files, so it is needed if you are working in production mode. In debug mode this is done automatically. For be sure, do that manually just dropping the prod folder under var if you are in 3.x, in 2.x under app.
清除缓存的命令对于2.x是:
The command to clear the cache for 2.x is:
php app/console cache:clear --env=prod
这篇关于未捕获PHP异常Doctrine\ORM\ORMException:“未知实体名称空间别名”AppBundle'。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!