我刚刚开始使用 Composer 开始我的第一个项目,并想为其设置数据库和类。然而我被困住了。我在 prod.log 中收到上述错误
我在这里遵循了本教程:http://symfony.com/doc/current/book/doctrine.html 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();
我收到错误
[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)"} []
我实际上如何让它发挥作用/我刚刚开始该项目。不过,教义创建了类。我有这样的
/src
/src/AppBundle/
/src/AppBundle/Entity
Product.php
/src/AppBundle/Repository
ProductRepository.php
另外,在 Product.php 中,这是在注释的注释中(如果有帮助的话)
* @ORM\Entity(repositoryClass="AppBundle\Repository\ProductRepository")
另外,当尝试这个命令时php bin/console doctrine:generate:entities AppBundle
重新创建实体我没有收到任何错误消息。
我越来越
Generating entities for bundle "AppBundle"
> backing up Product.php to Product.php~
> generating AppBundle\Entity\Product