Doctrine and LIKE query

后端 未结 5 1814
滥情空心
滥情空心 2021-02-06 20:44

I have entity for Doctrine:



        
5条回答
  •  悲哀的现实
    2021-02-06 20:53

    You can use the createQuery method (direct in the controller) :

    $query = $em->createQuery("SELECT o FROM AcmeCodeBundle:Orders o WHERE o.OrderMail =  :ordermail and o.Product like :searchterm")
    ->setParameter('searchterm', '%'.$searchterm.'%')
    ->setParameter('ordermail', 'some@email.com');
    

    You need to change AcmeCodeBundle to match your bundle name

    Or even better - create a repository class for the entity and create a method in there - this will make it reusable

提交回复
热议问题