我正在尝试在Symfony 4中访问查询字符串参数。
namespace App\Controller;
use Symfony\Component\HttpFoundation\RequestStack;
class Home extends Controller {
private $request;
public function __construct(RequestStack $request){
$this->request = $request;
}
public function getQueryString(){
$req = $this->request->getCurrentRequest();
print_r($req); // see all the request data
// $req -> grab the query parameters
// return query parameters
}
}
我正在使用 RequestStack
,当我打印 getCurrentRequest()
的结果时能够看到许多请求数据(包括我需要的查询参数),但大部分方法都是 private
,我不能访问它们。
在Symfony中,如何获取请求的URL组件(包括查询参数)?