Symfony 2 Forward Request passing along GET/POST params

后端 未结 4 2088
醉酒成梦
醉酒成梦 2021-01-04 09:26

Is it possible to forward a request, passing along all GET/POST params?

I think if I just do

$this->forward(\'dest\')

I will g

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-04 09:56

    All POST param are automatically forwarded. No action is needed to have POST param in the target controller. But you have to explicitly pass query (GET) params and path params. The forward method take 2 optionals parameter representing respectively the pathParam and the queryParam arrays. You can just pass all the query param from the current request

    public testAction(Request $request){
        $pathParam = array(); //Specified path param if you have some
        $queryParam = $request->query->all(); 
        $response = $this->forward("AcmeBundle:Forward:new", $pathParam, $queryParam);
    }
    

提交回复
热议问题