我正在使用symfony3: 我想在我的查询中使用。
$repository = $this->getDoctrine()->getRepository('AppBundle:ABC');
echo $searchstring = "LIKE '%".$searchtxt."%'"; die;
$res=$repository->findBy(array('fname' => $searchstring));
$normalizer = new ObjectNormalizer();
$encoder = new JsonEncoder();
$serializer = new Serializer(array($normalizer), array($encoder));
$response=$serializer->serialize($res, 'json'); // Output: {"name":"foo","sportsman":false}
return new Response($response);
返回 null
任何人都可以建议我吗?
答案 0 :(得分:2)
Doctrine资源库的find*()
方法不允许使用LIKE
执行查询以进行比较。您需要编写自定义DQL查询(请参阅Querying for Objects with DQL和Doctrine Query Language):
$query = $em->createQuery("SELECT abc FROM AppBundle:ABC abc WHERE fname LIKE :fname");
$query->setParameter('fname', 'LIKE "%'.$searchtxt.'%"');
$result = $query->getResult();