繁体   English   中英

Symfony:无法自动装配“Controller:method()”的参数 $injectedVar:它引用 class“App\Entity\Entity”,但不存在此类服务

[英]Symfony: Cannot autowire argument $injectedVar of "Controller:method()": it references class "App\Entity\Entity" but no such service exists

当您尝试在控制器的 arguments 中注入实体时,可能会发生此错误:

controller:

#[Route('/{id}', name: 'details')]
public function details(Post $post): Response
{
    return $this->render("post/details.html.twig", [
        "post" => $post
    ]);
}

错误:

Cannot autowire argument $post of "App\Controller\PostController::details()": it references class "App\Entity\Post" but no such service exists.

如果遇到此错误,请尝试安装以下软件包:

composer require form validator security-csrf annotations 

它为我修复了它(我猜我只需要注释,我发布了完整的要求以防万一)。

在创建 symfony/skeleton 项目时你可能会遇到这个错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM