You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Sylius/Symfony 5中EntryController提示未设置容器报错怎么解决?

解决方案

问题1:路由配置与控制器方法名不匹配

你当前控制器中定义的处理方法名为indexAction,但路由sylius_complete_order_form的配置中指定的控制器方法为index,二者不一致导致调用逻辑异常,容器注入流程无法正常触发。
两种修正方案二选一即可:

  • 修改路由配置(src/Resources/config/routing/admin/order_form.yml)的controller字段:
    sylius_complete_order_form:
      path: /order/form
      methods: [GET]
      controller: App\Controller\EntryController::indexAction # 修正为完整方法名
    
  • 或者修改控制器方法名(符合Symfony 5+的无后缀命名规范):
    // 将方法名从indexAction改为index
    public function index(Request $request): Response
    {
       dd('THIS CONTROLLER IS WORKING!');
    }
    

问题2:控制器服务未开启自动配置

从debug:container的输出可以看到,你的控制器Autoconfigured属性为no,继承AbstractController的控制器需要开启自动配置才能自动识别为服务订阅者、完成容器注入。
修改config/services.yaml中控制器的服务配置,新增autoconfigure: true:

App\Controller\:
    resource: '../src/Controller'
    public: true
    autowire: true
    autoconfigure: true # 新增该行
    tags: ['controller.service_arguments']

验证操作

修改完成后执行php bin/console cache:clear清理缓存,再执行php bin/console debug:router sylius_complete_order_form确认路由对应的控制器配置正确,重新访问路径即可恢复正常。


内容的提问来源于stack exchange,提问作者Matthew Dejager

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.24 20:54:04