小编sin*_*ina的帖子

symfony 中的构造函数注入

我想在我的构造函数中使用 Request 类,这是我想运行服务器时它给我的错误:

无法自动装配服务“AppBundle\Controller\DetectServiceDetailController”:方法“__construct()”的参数“$request”引用类“Symfony\Component\HttpFoundation\Request”,但不存在这样的服务。它无法自动注册,因为它来自不同的根命名空间。

我的代码:

<?php

namespace AppBundle\Controller;

use Symfony\Component\HttpFoundation\Request;

class DetectServiceDetailController
{
    public $request;

    public function __construct(Request $request)
    {
        $this->request = $request;
        $serviceType = $this->request->query->get('type');
        return $serviceType;

    }

}
Run Code Online (Sandbox Code Playgroud)

php symfony

5
推荐指数
1
解决办法
4252
查看次数

标签 统计

php ×1

symfony ×1