dougan1205 2018-09-27 13:49
浏览 75

Symfony 3.4 - 自动服务线在方法中不起作用

I'm relatively new to Symfony, and I'm having trouble some trouble. I'm trying to type hint a custom RequestValidator class in the method being called when the endpoint is called.

Using Symfony 3.4

However, I am getting the following error:

Controller "ApiBundle\Endpoints\Healthcheck\v1\Index::check()" requires that you provide a value for the "$request" argument. Either the argument is nullable and no null value has been provided, no default value has been provided or because there is a non optional argument after this one.

Here is my setup:

services.yml file

           autowire: true
           autoconfigure: true



path: /healthcheck
controller: ApiBundle\Endpoints\Healthcheck\v1\Index::check
defaults: { _format: json }
    - GET

And then - inside the Index class, I have the following:


namespace ApiBundle\Endpoints\Healthcheck\v1;

use ApiBundle\Responses\ApiResponse;

class Index extends ApiResponse

      public function check(HealthcheckRequest $request) {


When I do debug:autowiring I see my HealthcheckRequest in the list.

Further, when I do the same and try type-hint in the constructor of the Index class, it all works.

And finally, if I try and type hint the Symfony/HttpFoundation/Request, inside the check() method, it instantiates it correctly.

In summary:

Not working :

  • check(HealthcheckRequest $request)


  • __construct(HealtcheckRequest $request)
  • check(SymfonyRequest $request)

Am I doing something wrong? Any help is appreciated.

  • 写回答

1条回答 默认 最新

  • doushe8577 2019-01-04 13:09

    It's part of services.yaml already in Symfony 4, but introduced in version 3.3, so this might help:

    # controllers are imported separately to make sure services can be injected
    # as action arguments even if you don't extend any base controller class
        resource: '../../Endpoints/*'
        tags: ['controller.service_arguments']
    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥30 关于#python#的问题:我想要的是这79个大特征对于房屋售价的最大的影响前十名(相关搜索:随机森林)
  • ¥15 使用matlab计算自定义特殊函数的二重积分,改变积分顺序所得的结果不同的问题?
  • ¥15 mysql做碎片化处理老是报错怎么办
  • ¥15 如何正确在vs2010中初始化map对象
  • ¥30 mmdet3d模型部署问题
  • ¥15 comsol仿真反射率、吸收率时峰值位置和深度不对!
  • ¥30 Visual Studio找不到sdk,如何解决?
  • ¥15 labview与机器之间网口通信发送指令
  • ¥15 迪杰斯特拉算法,考虑时延,带宽
  • ¥30 C#提交json字符串给http服务器