我是Doctrine ORM的新手,我在检索实体方面遇到了一些问题。
当我尝试检索我的实体时出现以下错误:
'AppBundle\Entity\FeedImport' was not found in the chain configured namespaces
我已经使用Symfony CLI实用程序mapping:import
生成我的实体yaml文件,并使用generate:entities
来创建模型。
我搜索过这个错误,大部分时间都是关于自定义包没有正确映射的。但因为我使用默认包我不知道应该是什么错。我是否需要使用更多信息配置学说?
我检查过的事情:
- AppBundle is active.
- AppBundle is registered.
- DefaultController of the AppBundle is loaded correctly.
- class FeedImport exists.
- class FeedImport has correct namespace.
- Tried switching naming strategy for doctrine. (It uses underscore namesping strategy by default, but my classes are in CamelCase)
你能看出出了什么问题吗?任何建议将不胜感激。以下是我的配置/设置详细信息。
DefaultController.php
public function indexAction(Request $request)
{
...........
$feedImport = $this->getDoctrine()->getRepository(FeedImport::class)->find(1);
...........
}
FeedImport.php类的命名空间:
namespace AppBundle\Entity
config.yml
doctrine:
dbal:
driver: pdo_mysql
host: '%database_host%'
port: '%database_port%'
dbname: '%database_name%'
user: '%database_user%'
password: '%database_password%'
charset: UTF8
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: '%kernel.project_dir%/var/data/data.sqlite'
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
#path: '%database_path%'
mapping_types:
enum: string
set: string
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
App Module结构:
AppBundle
├── AppBundle.php
├── Controller
│ └── DefaultController.php
├── Entity
│ ├── FeedImport.php
├── Repository
│ └── FeedImportRepository.php
└── Resources
└── config
└── doctrine
├── FeedImport.orm.yml