请我需要知道问题是什么,它应该起作用,但没有恢复结果。
有我的控制器:
public function searchAction()
{
$form = $this->createForm(new SearchCoursesType());
$request = $this->getRequest();
if($request->getMethod() == 'POST')
{
$form->bind($request);
if($form->isValid())
{
$em = $this->getDoctrine()->getManager();
$data = $this->getRequest()->request->get('formation_appbundle_scourse');
$courses = $em->getRepository('FormationAppBundle:Course')->findCoursesByParametres($data);
return $this->render('FormationAppBundle:Courses:coursesList.html.twig', array('courses' => $courses));
}
}
return $this->render('FormationAppBundle:Template:searchIndex.html.twig', array('form' => $form->createView()));
}
我在此类存储库中定义了搜索函数
public function findCoursesByParametres($data)
{
$query = $this->createQueryBuilder('a');
$query->where($query->expr()->like('a.title', ':title'))
->setParameters(array(
'title' => $data['title']
));
return $query->getQuery()->getResult();
}
使用简单的表格
{{ form_start(form) }}
{{ form_widget(form) }}
<input type="submit" value="Create" />
{{ form_end(form) }}
我认为它没有收集输入,但我找不到问题
更改您的功能存储库:
public function findCoursesByParametres($data)
{
$query = $this->createQueryBuilder('a')
->where('a.title LIKE :title')
->setParameters(array(
'title' => '%' . $data['title'] . '%'
));
return $query->getQuery()->getResult();
}