Използвам Symfony2.3
и в момента използвам EntityManager, както е показано в __construct()
Кой е по-добрият подход с помощта на EntityManager от __construct() или с използване във всеки метод? както е показано в public indexAction()
/**
* QuazBar controller.
*
*/
class QuazBarController extends Controller
{
public function __construct()
{
$this->em = $GLOBALS['kernel']->getContainer()->get('doctrine')->getManager();
}
/**
* Lists all QuazBar entities.
*
*/
public function indexAction(Request $request)
{
$session = $request->getSession();
$pagina = $request->query->get('page', 1);
$em = $this->getDoctrine()->getManager();
}