How to Forward Requests to another Controller

Though not very common, you can also forward to another controller internally
with the forward()
method. Instead of redirecting the user's browser, this makes an "internal"
sub-request and calls the defined controller. The forward() method returns
the Response object that is returned
from that controller:

1
2
3
4
5
6
7
8
9
10
11

publicfunctionindexAction($name){$response=$this->forward('AppBundle:Something:fancy',array('name'=>$name,'color'=>'green',));// ... further modify the response or return it directlyreturn$response;}

The array passed to the method becomes the arguments for the resulting controller.
The target controller method might look something like this: