Php – Symfony 2 – Call controller from another controller


I would like use a method of controller from another bundle, in my controller.

The method this->forward need a Response object, and i don't know how to use it.

public function indexAction($name)
$response = $this->forward('AcmeHelloBundle:Hello:fancy', array(
    'name'  => $name,
    'color' => 'green',

// ... further modify the response or return it directly

return $response;

And i saw that i can use service but i want to know if its the best solution or they are another.

Best Solution

$this->forward takes arguments in this order:

  1. Logical Name of controller action in string format i.e. 'AcmeHelloBundle:Hello:fancy'
  2. Parameters to be passed as request variables in array format i.e. array( 'name' => $name, 'color' => 'green', )

These parameters can be accessed in the controller using request access functions.

Related Question