@@ -541,7 +541,7 @@ on its ``id`` value::
541541 public function showAction($productId)
542542 {
543543 $product = $this->getDoctrine()
544- ->getRepository('AppBundle: Product' )
544+ ->getRepository(Product::class )
545545 ->find($productId);
546546
547547 if (!$product) {
@@ -565,18 +565,18 @@ job is to help you fetch entities of a certain class. You can access the
565565repository object for an entity class via::
566566
567567 $repository = $this->getDoctrine()
568- ->getRepository('AppBundle: Product' );
568+ ->getRepository(Product::class );
569569
570570.. note ::
571571
572- The ``AppBundle:Product `` string is a shortcut you can use anywhere
572+ You can also use ``AppBundle:Product `` syntax. This string is a shortcut you can use anywhere
573573 in Doctrine instead of the full class name of the entity (i.e. ``AppBundle\Entity\Product ``).
574574 As long as your entity lives under the ``Entity `` namespace of your bundle,
575575 this will work.
576576
577577Once you have a repository object, you can access all sorts of helpful methods::
578578
579- $repository = $this->getDoctrine()->getRepository('AppBundle: Product' );
579+ $repository = $this->getDoctrine()->getRepository(Product::class );
580580
581581 // query for a single product by its primary key (usually "id")
582582 $product = $repository->find($productId);
@@ -599,7 +599,7 @@ Once you have a repository object, you can access all sorts of helpful methods::
599599You can also take advantage of the useful ``findBy() `` and ``findOneBy() `` methods
600600to easily fetch objects based on multiple conditions::
601601
602- $repository = $this->getDoctrine()->getRepository('AppBundle: Product' );
602+ $repository = $this->getDoctrine()->getRepository(Product::class );
603603
604604 // query for a single product matching the given name and price
605605 $product = $repository->findOneBy(
@@ -635,7 +635,7 @@ you have a route that maps a product id to an update action in a controller::
635635 public function updateAction($productId)
636636 {
637637 $em = $this->getDoctrine()->getManager();
638- $product = $em->getRepository('AppBundle: Product' )->find($productId);
638+ $product = $em->getRepository(Product::class )->find($productId);
639639
640640 if (!$product) {
641641 throw $this->createNotFoundException(
@@ -681,7 +681,7 @@ Querying for Objects
681681You've already seen how the repository object allows you to run basic queries
682682without any work::
683683
684- $repository = $this->getDoctrine()->getRepository('AppBundle: Product' );
684+ $repository = $this->getDoctrine()->getRepository(Product::class );
685685
686686 $product = $repository->find($productId);
687687 $product = $repository->findOneByName('Keyboard');
@@ -742,7 +742,7 @@ depends on dynamic conditions, as your code soon becomes hard to read with
742742DQL as you start to concatenate strings::
743743
744744 $repository = $this->getDoctrine()
745- ->getRepository('AppBundle: Product' );
745+ ->getRepository(Product::class );
746746
747747 // createQueryBuilder() automatically selects FROM AppBundle:Product
748748 // and aliases it to "p"
0 commit comments