Mus*_*abe 3 php doctrine entity-framework symfony doctrine-orm
我刚刚从composer开始了我的第一个项目,并想为其建立数据库和类。但是我被困住了。我在prod.log中遇到上述错误
我在这里遵循了本教程:http : //symfony.com/doc/current/book/doctrine.html
我创建了数据库
php bin/console doctrine:database:create
然后想创建一个实体
php bin/console doctrine:generate:entity
当要求The Entity shortcut name我输入AppBundle:Product
然后创建数据库字段等
我收到这个消息
实体产生
生成实体类src / AppBundle / Entity / Product.php:好的!
生成存储库类src / AppBundle / Repository / ProductRepository.php:好的!一切都好!现在开始工作:)。
听起来一切正常,对吧?
现在在我ProductController用这个
$products = $this->getDoctrine()
->getRepository('AppBundle:Product')
->findAll();
Run Code Online (Sandbox Code Playgroud)
而我得到了错误
[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)"} []
Run Code Online (Sandbox Code Playgroud)
我也试过
->getRepository('AppBundle\Entity\Product')
Run Code Online (Sandbox Code Playgroud)
但在这里我收到消息
[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)"} []
Run Code Online (Sandbox Code Playgroud)
我实际上是如何工作的/我刚刚开始这个项目。教义虽然创建了类。我有这样的
/src
/src/AppBundle/
/src/AppBundle/Entity
Product.php
/src/AppBundle/Repository
ProductRepository.php
Run Code Online (Sandbox Code Playgroud)
另外,在Product.php中,它在注释的注释中(如果有帮助)
* @ORM\Entity(repositoryClass="AppBundle\Repository\ProductRepository")
Run Code Online (Sandbox Code Playgroud)
另外,当尝试使用此命令php bin/console doctrine:generate:entities AppBundle重新创建实体时,我没有收到任何错误消息。
我越来越
Generating entities for bundle "AppBundle"
> backing up Product.php to Product.php~
> generating AppBundle\Entity\Product
Run Code Online (Sandbox Code Playgroud)
解决方案是删除缓存文件,因此如果您在生产模式下工作,则需要这样做。在调试模式下,这是自动完成的。可以肯定的是,如果您位于3.x中,位于app下的2.x中,则只需将prod文件夹拖放到var下即可。
清除2.x缓存的命令是:
php app/console cache:clear --env=prod
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2793 次 |
| 最近记录: |