I believe that the flow of Symfony2 is the following : Request -> Controller -> Response.
Actually, with this code, MessageController is not returning a response Object, but only a value for another Controller :
MessageController of Compagny/MessageBundle :
<?php
class MessageController extends Controller
{
public function getAction()
{
$message = "I display this message";
return $message; // It's not a new Response object, it returns only a value
}
}
InterfaceController of Compagny/InterfaceBundle :
<?php
class InterfaceController extends Controller
{
public function indexAction()
{
$data = $this->forward('MessageBundle:Message:get');
$response = new Response($data);
return $response; // This one return a Response object
}
}
Is this code a bad practice ?
Yes. Because if you decide later to use Message::get directly, you won’t be able to do it or fix it without changing InterfaceController.
I suggest this: