Doctrine and Like query symfony2 -
Doctrine and Like query symfony2 -
i have search bar in page , action in in charge of looking user search :
public function searchaction(request $request){ $em = $this->container->get('doctrine')->getentitymanager(); $evenements= $em->getrepository('mql14mqlmebundle:evenement')->findall(); if ('post' === $request->getmethod()) { $search = $request->get('search'); $query = $this->container->get('doctrine')->getentitymanager()->createquery( 'select e mql14mqlmebundle:evenement e e.nom :search') ->setparameter('search', $search); $resultats = $query->getresult(); homecoming $this->container->get('templating')->renderresponse('mql14mqlmebundle:event:search.html.twig', array( 'resultats'=>$resultats, )); } homecoming $this->listeraction(); }
it's working if user set exact name of event in database, want create search possible if it's part of name, tried in query:
$query = $this->container->get('doctrine')->getentitymanager()->createquery( 'select e mql14mqlmebundle:evenement e e.nom :%search%') ->setparameter('search', $search);
but i'm getting error: invalid parameter format, : given, :name or ?num expected.
try alter parameter this:
$query = $this ->container ->get('doctrine') ->getentitymanager() ->createquery( 'select e mql14mqlmebundle:evenement e e.nom :search' ) ->setparameter('search', '%'.$search.'%');
symfony2 doctrine dql
Comments
Post a Comment