php - Symfony 表实体本身也被识别为存储库
问题描述
Symfony 和 StackOverflow 作为 OP 的新手。
我正在尝试在 Symfony(4.3.2) 上添加新的 mysql 表实体和存储库,并在测试时卡住了。
我真的很感谢有人的帮助。
我得到的错误是
[2020-07-13 03:25:59] request.CRITICAL: Uncaught PHP Exception RuntimeException: "The "App\Entity\Foo" entity has a repositoryClass set to "App\Repository\Foo", but this is not a valid class. Check your class naming. If this is meant to be a service id, make sure this service exists and is tagged with "doctrine.repository_service"." at /var/www/html/bar_project/vendor/doctrine/doctrine-bundle/Repository/ContainerRepositoryFactory.php line 66 {"exception":"[object] (RuntimeException(code: 0): The \"App\\Entity\\Foo\" entity has a repositoryClass set to \"App\\Repository\\Foo\", but this is not a valid class. Check your class naming. If this is meant to be a service id, make sure this service exists and is tagged with \"doctrine.repository_service\". at /var/www/html/bar_project/vendor/doctrine/doctrine-bundle/Repository/ContainerRepositoryFactory.php:66)"} []
其中Foo
/App/Entity/ 是 table 的实体foo
。
问题是它试图Foo
在 App/Repository/ 处引用它的存储库,它不存在,但不FooRepository
存在。(根据来自的评论更新了本段Jakumi
)
(FooController.php)
$repository = $this->getDoctrine()->getRepository(Foo::class);
(Foo.php)
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="foo")
* @ORM\Entity(repositoryClass="App\Repository\FooRepository") // *1
*/
class Foo
{
...
(FooRepository.php)
<?php
namespace App\Repository;
use App\Entity\Foo;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Symfony\Bridge\Doctrine\RegistryInterface;
/**
* @method Foo|null find($id, $lockMode = null, $lockVersion = null)
* ...
*/
class FooRepository extends ServiceEntityRepository
{
...
我觉得神秘的一件事是,即使我删除了相同的错误日志,仍然会显示*1
.
(我认为我的纱线手表和缓存清除正常工作。)
附加信息 1
(doctrine.yaml)
doctrine:
dbal:
# configure these for your database server
driver: 'pdo_mysql'
server_version: '8.0'
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
# dbname:
# host:
# port:
# user:
# password:
url: '%env(resolve:DATABASE_URL)%'
options:
1002: 'SET sql_mode=(SELECT REPLACE(@@sql_mode, "ONLY_FULL_GROUP_BY", ""))'
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
metadata_cache_driver: apcu
result_cache_driver: apcu
query_cache_driver: apcu
connection: ~
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
dql:
string_functions:
group_concat: DoctrineExtensions\Query\Mysql\GroupConcat
date_format: DoctrineExtensions\Query\Mysql\DateFormat
解决方案
推荐阅读
- java - 多维数组到缩进列表
- javascript - 在 Node 中暂停和恢复下载文件
- javascript - 在地图循环中生成多个参考
- entity-framework - 无法访问新创建对象的导航属性
- python - 如何从 .npy 文件中仅加载几行?
- python - 如果我已经将列表定义为变量,如何检查变量是否为列表类型?
- python - 如何使用 Django 和 BeautifulSoup 在 html 中呈现 IMDB 信息?
- javascript - 尝试使用 NodeJS 生成自述文件
- go - 或者 golang 模板中的语句结合 gt/lt (greaterThan, lowerThan)
- python - 为什么我的 DataFrame 没有保存到 Pandas_python 中的变量 q5