Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Use controller method injection instead of the constructor
  • Loading branch information
javiereguiluz authored Jan 7, 2018
commit 3492028a0e583e0f7167572ce8e31b64d278e9f2
14 changes: 3 additions & 11 deletions doctrine/multiple_entity_managers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -235,18 +235,10 @@ the default entity manager (i.e. ``default``) is returned::

class UserController extends Controller
{
protected $em;

public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}

public function indexAction()
public function indexAction(EntityManagerInterface $em)
{
// All 4 return the "default" entity manager, though using
// dependency injection is a best practice
$em = $this->em;
// These methods also return the default entity manager, but it's preferred
// to get it by inyecting EntityManagerInterface in the action method
$em = $this->getDoctrine()->getManager();
$em = $this->getDoctrine()->getManager('default');
$em = $this->get('doctrine.orm.default_entity_manager');
Expand Down