Hi I'm developping two applications now with Symfony 3,I have the same problem in both, I want to integrate a search form into twig with render(controller()), the problem is that redirecting to the result page gives me this error
An exception has been thrown during the rendering of a template ("Error when rendering "http://localhost/project/web/app_dev.php/index" (Status code is 302).").
this is my controller
class ProductController extends Controller
{
public function resultsAction($criteria){
$em=$this->getDoctrine()->getManager();
$listProducts = $em->getRepository('ProjectProductBundle:Product')->getListBy($criteria);
return $this->render('ProjectFrontBundle:Front:results.html.twig', array('listProducts'=>$listProducts));
}
public function SearchByNameAction(Request $request){
$product = new Product();
$form=$this->get('form.factory')->create(ProductType::class,$product);
if($request->isMethod('post') && $form->handleRequest($request)->isValid()){
$em=$this->getDoctrine()->getManager();
$criteria = $form["name"]->getData();
return $this->redirectToRoute('project_product_results', array('criteria'=>$criteria));
}
return $this->render('ProductFrontBundle:Front:search.html.twig',array('form'=>$form->createView()));
}
}
this is my function in repository
class ProductRepository extends \Doctrine\ORM\EntityRepository
{
public function getListBy($criteria)
{
$qb = $this->createQueryBuilder('p')
->where('p.name LIKE :criteria')
->setParameter('criteria', '%'.$criteria.'%');
return $qb->getQuery()->getResult();
}
}
this is my view on twig
<div>
{% block search_body %}
{{ render(controller('ProductProductBundle:Product:SearchByName',{'request': app.request,})) }}
{% endblock %}
</div>
this is the view on twig resultss page
<ul>
{% for product in listProducts %}
<li>{{ product.name }}</li>
{% endfor %}
</ul>
I need your help how can i solve this problem ?