I am new to symfony 2.8. I do the same code pattern in each of my controllers to get the same data, put in different views, following this pattern:
public function someMethod(Request $request){
//1) instanciate entity manager
$em = $this->getDoctrine()->getManager();
//2) Fetch some datas ..
$datas = $em->getRepository('MyCustomBundle:Entity')->findAll();
$otherDatas = $em->getRepository('MyCustomBundle:AnotherEntity')->findAll();
//3) Inject datas into view
return $this->render('MyCustomBundle:Views:myview.html.twig', array('data'=>$datas,'otherDatas'=>$otherDatas));
}
Is it possible to factorize all the getRepositories calls and arrays injection into a separated class ?
thanks for your help,