From what I can tell from your snippet, you are looking for something like this:
$entityManager->getRepository('PfBlogBundle:Article') ->findBy( array( 'key' => 'value' ) );
Where the key is the / field property and the value is the value to look for. Check out the symfony man page. The bit you are using is Extracting objects from the database .
To use like
in the where clause, refer to this SO question on how to use setParameter
. You will receive a request:
$repo = $entityManager->getRepository('PfBlogBundle:Article'); $query = $repo->createQueryBuilder('a') ->where('a.title LIKE :title') ->setParameter('title', '%'.$data['search'].'%') ->getQuery();
Of course, add wildcards to suit your needs. I put the value of $data['search']
in two %
wildcards, which is slow, but again: I donโt know what you are actually doing. Perhaps all you need is case insensitivity like
, in which case %
can be left unchanged ...
According to your previous questions (BTW: think about accepting an answer from time to time):
public function searchAction(Request $request) { $data = $request->get->all(); $repo = $this->getDoctrine() ->getRepository('PfBlogBundle:Article'); $query = $repo->createQueryBuilder('a') ->where('a.title LIKE :title') ->setParameter('title', '%'.$data['search'].'%') ->getQuery(); $paginator = $this->get('knp_paginator'); $pagination = $paginator->paginate( $query->getResults(),
But this is just a rough fix, Google doctrine-symfony pagination , there are many detailed blog posts on this subject
source share