milardovich

Custom query doctrine symfony

Aug 23rd, 2017
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.55 KB | None | 0 0
  1.     /**
  2.      * Lists all Article entities.
  3.      *
  4.      * @Route("/search/{q}", name="article_search")
  5.      * @Method("GET")
  6.      */
  7.     public function searchAction($q)
  8.     {
  9.         $em = $this->getDoctrine()->getManager();
  10.  
  11.  
  12.  
  13.         $query = $em->createQuery("SELECT a FROM AppBundle\Entity\Product a WHERE a.title LIKE '%$q%'");
  14.         $products = $query->getResult(); // array of Company objects
  15.  
  16.         return $this->render('product/search.html.twig', array(
  17.             'products' => $products,
  18.             'query' => $q
  19.         ));
  20.     }
Advertisement
Add Comment
Please, Sign In to add comment