【发布时间】:2019-02-18 20:25:46
【问题描述】:
我正在尝试访问 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 组件(包括查询参数)?
【问题讨论】:
标签: php symfony request symfony4 php-7.2