Search code examples
formssymfonycontrollertwigbundle

variable 'filterForm' does not exist


i want to do a search form using a bundle "PetkoparaMultiSearchBundle" but i get this error when i try to put the form on my twig using

 {{ form_rest(filterForm) }}

here's my searchtype.php

   class SearchType extends AbstractType{

   public function buildForm(FormBuilderInterface $builder, array $options)
  {
  $builder->add('search', MultiSearchType::class, array(
        'class' => 'SpoiledCarFrontOfficeBundle:Voiture'));
  }
  }

and here's my controller

 * Search a Voiture .
 *
 * @Route("/profile/shop", name="fos_user_profile_listTable")
 * @Method({"GET", "POST"})
 */    
  public function listTableAction(Request $request)
{
$search = $request->get('search');
$em = $this->getDoctrine()->getManager();
$queryBuilder = $em->getRepository('SpoiledCarFrontOfficeBundle:Voiture')-  >createQueryBuilder('e');
$filterForm = $this->createForm('SpoiledCarFrontOfficeBundle\Form\SearchType');

// Bind values from the request
 $filterForm->handleRequest($request);

 if ($filterForm->isValid()) {
    // Build the query from the given form object
    $queryBuilder = $this->get('petkopara_multi_search.builder')->searchForm($queryBuilder, $filterForm->get('search'));
}

}

what i'm doing wrong ?


Solution

  • You have to pass the form to the view. Add this to your controller.

     return $this->render(
         'Bundle:Controller:view.html.twig',
          array(
              'filterForm' => $filterForm->createView()
          )
     );