Skip to content

Commit 3492028

Browse files
Use controller method injection instead of the constructor
1 parent f9091b0 commit 3492028

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

doctrine/multiple_entity_managers.rst

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -235,18 +235,10 @@ the default entity manager (i.e. ``default``) is returned::
235235

236236
class UserController extends Controller
237237
{
238-
protected $em;
239-
240-
public function __construct(EntityManagerInterface $em)
241-
{
242-
$this->em = $em;
243-
}
244-
245-
public function indexAction()
238+
public function indexAction(EntityManagerInterface $em)
246239
{
247-
// All 4 return the "default" entity manager, though using
248-
// dependency injection is a best practice
249-
$em = $this->em;
240+
// These methods also return the default entity manager, but it's preferred
241+
// to get it by inyecting EntityManagerInterface in the action method
250242
$em = $this->getDoctrine()->getManager();
251243
$em = $this->getDoctrine()->getManager('default');
252244
$em = $this->get('doctrine.orm.default_entity_manager');

0 commit comments

Comments
 (0)