Reputation: 335
I got two Controllers:
class FirstController extends Controller
{
/**
* @Route("/first")
*/
public function indexAction()
{
$second = new SecondController();
$second->doit();
}
}
class SecondController extends Controller
{
public function doit()
{
$render = $this->renderView('::base.html.twig');
//write $render to disk
}
}
Instead of 'done' being written to my screen, I got error:
What am I doing wrong?
Upvotes: 1
Views: 278
Reputation: 23255
You are not supposed to instantiate controllers yourself. The framework is supposed to do that for you. If you are in controller1, and want controller2 to actually handle the request, which could use some explanation on your part, you need to forward to it, like this : $this->forward('MyBundle:MyController:myaction)
Also, you should maybe have your doit
method in a service. Controllers are supposed to stay skinny, and care only about HTTP:
Upvotes: 2