Symfony 4美好的一天,告诉我为了使用存储库需要修复什么doctrine?现在,当我尝试访问该页面时,出现以下错误:
在链配置的命名空间 App\Entity 中找不到类“App\Repository\PageModulesRepository”
存储库本身:
namespace App\Repository;
use App\Entity\PageModules;
use Doctrine\ORM\EntityRepository;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Symfony\Bridge\Doctrine\RegistryInterface;
class PageModulesRepository extends EntityRepository
{
public function __construct()
{
}
}
控制器本身
namespace App\Controller;
use App\Repository\PageModulesRepository;
use Doctrine\Common\Annotations\AnnotationReader;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;
class ApiController extends Controller
{
/**
* @Route("/api", name="api")
*/
public function index()
{
$do = $this->getDoctrine();
$treeR = $do->getRepository(PageModulesRepository::class);
return $this->json([
'message' => 'Welcome to your new controller!',
'path' => 'src/Controller/ApiController.php',
]);
}
}
我怀疑问题可能出在此处:
教义配置:
parameters:
# Adds a fallback DATABASE_URL if the env var is not set.
# This allows you to run cache:warmup even if your
# environment variables are not available yet.
# You should not need to change this value.
env(DATABASE_URL): ''
doctrine:
dbal:
# configure these for your database server
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
url: '%env(resolve:DATABASE_URL)%'
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
我试图删除映射部分:在配置中然后它只是说
在链配置的命名空间中找不到类“App\Repository\PageModulesRepository”
告诉我如何解决?
存储库是通过实体的名称而不是存储库的类来查找的: