Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3492028

Browse files
Use controller method injection instead of the constructor
1 parentf9091b0 commit3492028

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)

[8]ページ先頭

©2009-2025 Movatter.jp