Skip to content

Commit 8f66dbb

Browse files
committed
minor #11062 Persisting : forget a "use" statement ? (Rom1deTroyes)
This PR was squashed before being merged into the 4.2 branch (closes #11062). Discussion ---------- Persisting : forget a "use" statement ? The `ProductController` created above (L332) by `$ php bin/console make:controller ProductController` use this generated code : ```php return $this->render('product/index.html.twig', [ 'controller_name' => 'ProductController', ]); ``` But we modify this to returns a `new Response('...')` : ```php return new Response('Saved new product with id '.$product->getId()); ``` so we must add a `use Symfony\Component\HttpFoundation\Response;` statement to work. Not sure if it's better to force good habits of "search and debug", or just having a "cut n' paste" working example ? (-: Commits ------- d1e794f Persisting : forget a \"use\" statement ?
2 parents 0a6ad93 + d1e794f commit 8f66dbb

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

doctrine.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,8 @@ and save it!
340340
namespace App\Controller;
341341
342342
// ...
343+
use Symfony\Component\HttpFoundation\Response;
344+
343345
use App\Entity\Product;
344346
345347
class ProductController extends AbstractController
@@ -386,17 +388,17 @@ Take a look at the previous example in more detail:
386388

387389
.. _doctrine-entity-manager:
388390

389-
* **line 16** The ``$this->getDoctrine()->getManager()`` method gets Doctrine's
391+
* **line 18** The ``$this->getDoctrine()->getManager()`` method gets Doctrine's
390392
*entity manager* object, which is the most important object in Doctrine. It's
391393
responsible for saving objects to, and fetching objects from, the database.
392394

393-
* **lines 18-21** In this section, you instantiate and work with the ``$product``
395+
* **lines 20-23** In this section, you instantiate and work with the ``$product``
394396
object like any other normal PHP object.
395397

396-
* **line 24** The ``persist($product)`` call tells Doctrine to "manage" the
398+
* **line 26** The ``persist($product)`` call tells Doctrine to "manage" the
397399
``$product`` object. This does **not** cause a query to be made to the database.
398400

399-
* **line 27** When the ``flush()`` method is called, Doctrine looks through
401+
* **line 29** When the ``flush()`` method is called, Doctrine looks through
400402
all of the objects that it's managing to see if they need to be persisted
401403
to the database. In this example, the ``$product`` object's data doesn't
402404
exist in the database, so the entity manager executes an ``INSERT`` query,

0 commit comments

Comments
 (0)