-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Replacing EntityManagerInterface -> $this->getDoctrine()->getManager(); #8089
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -551,10 +551,11 @@ a controller, this is pretty easy. Add the following method to the | |
use Doctrine\ORM\EntityManagerInterface; | ||
use Doctrine\Common\Persistence\ManagerRegistry; | ||
|
||
public function createAction(EntityManagerInterface $em) | ||
public function createAction() | ||
{ | ||
// or fetch the em via the container | ||
// $em = $this->get('doctrine')->getManager(); | ||
// you can fetch the EntityManager via $this->getDoctrine() | ||
// or you can add an argument to your action: createAction(EntityManagerInterface $em) | ||
$em = $this->get('doctrine')->getManager(); | ||
|
||
$product = new Product(); | ||
$product->setName('Keyboard'); | ||
|
@@ -571,8 +572,9 @@ a controller, this is pretty easy. Add the following method to the | |
} | ||
|
||
// if you have multiple entity managers, use the registry to fetch them | ||
public function editAction(ManagerRegistry $doctrine) | ||
public function editAction() | ||
{ | ||
$doctrine = $this->getDoctrine(); | ||
$em = $doctrine->getManager(); | ||
$em2 = $doctrine->getManager('other_connection') | ||
} | ||
|
@@ -586,7 +588,7 @@ Take a look at the previous example in more detail: | |
|
||
.. _doctrine-entity-manager: | ||
|
||
* **line 10** The ``EntityManagerInterface`` type-hint tells Symfony to pass you Doctrine's | ||
* **line 13** The ``$this->getDoctrine()->getManager()`` method gets Doctrine's | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I verified all the lines are correct via platform.sh |
||
*entity manager* object, which is the most important object in Doctrine. It's | ||
responsible for saving objects to, and fetching objects from, the database. | ||
|
||
|
@@ -633,11 +635,10 @@ Fetching an object back out of the database is even easier. For example, | |
suppose you've configured a route to display a specific ``Product`` based | ||
on its ``id`` value:: | ||
|
||
use Doctrine\ORM\EntityManagerInterface; | ||
|
||
public function showAction($productId, EntityManagerInterface $em) | ||
public function showAction($productId) | ||
{ | ||
$product = $em->getRepository('AppBundle:Product') | ||
$product = $this->getDoctrine() | ||
->getRepository('AppBundle:Product') | ||
->find($productId); | ||
|
||
if (!$product) { | ||
|
@@ -727,11 +728,11 @@ Updating an Object | |
Once you've fetched an object from Doctrine, updating it is easy. Suppose | ||
you have a route that maps a product id to an update action in a controller:: | ||
|
||
use Doctrine\ORM\EntityManagerInterface; | ||
|
||
public function updateAction($productId, EntityManagerInterface $em) | ||
public function updateAction($productId) | ||
{ | ||
$product = $em->getRepository('AppBundle:Product')->find($productId); | ||
$product = $this->getDoctrine() | ||
->getRepository('AppBundle:Product') | ||
->find($productId); | ||
|
||
if (!$product) { | ||
throw $this->createNotFoundException( | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,13 +32,11 @@ create your form:: | |
|
||
// src/AppBundle/Controller/DefaultController.php | ||
use AppBundle\Form\TaskType; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
|
||
// ... | ||
public function newAction(EntityManagerInterface $em) | ||
public function newAction() | ||
{ | ||
// or fetch the em via the container | ||
// $em = $this->get('doctrine')->getManager(); | ||
$em = $this->get('doctrine')->getManager(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're not using |
||
|
||
$task = ...; | ||
$form = $this->createForm(TaskType::class, $task, array( | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be removed