This should be simple but I can't find a working example. Here's a controller method that throws the error "Invalid parameter number: number of bound variables does not match number of tokens". I'm posting the "searchterm" variable successfully but can't get the query to work. What is missing? Thanks!
public function searchAction()
{
$request = $this->getRequest();
$searchterm = $request->get('searchterm');
$em = $this->getDoctrine()->getEntityManager();
$query = $em->createQuery("SELECT n FROM AcmeNodeBundle:Node n WHERE n.title LIKE '% :searchterm %'")
->setParameter('searchterm', $searchterm);
$entities = $query->getResult();
return array('entities' => $entities);
}
Working example from my Symfony2 project:
$qb = $this->createQueryBuilder('u');
$qb->where(
$qb->expr()->like('u.username', ':user')
)
->setParameter('user','%Andre%')
->getQuery()
->getResult();