gpt4 book ai didi

php - 您忘记将 Controller 注册为服务或错过了用 "controller.service_arguments"标记它?

转载 作者:行者123 更新时间:2023-12-02 18:18:36 27 4
gpt4 key购买 nike

我是 symfony 的初学者。当我在 symphony 中调用 get API 时,显示如下错误。

RuntimeException
HTTP 500 Internal Server Error
Could not resolve argument $salesteamRepository of "App\Controller\SalesController::index()", maybe you forgot to register the controller as a service or missed tagging it with the "controller.service_arguments"?

最佳答案

它的发生是因为你当前的类不是服务,你在类中使用的所有类都不是由 symfony 自动注入(inject)的。

如果你想为你创建的所有类自动依赖注入(inject),你可以将你的类扩展到AbstractController,像这样

class MyPet extends AbstractController{}

官方 symfony 文档中已经提到了这一点。

In Symfony, a controller does not need to be registered as a service.But if you're using the default services.yaml configuration, and yourcontrollers extend the AbstractController class, they areautomatically registered as services. This means you can usedependency injection like any other normal service.

关于php - 您忘记将 Controller 注册为服务或错过了用 "controller.service_arguments"标记它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71201327/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com