【问题标题】:variable 'filterForm' does not exist变量“filterForm”不存在
【发布时间】:2017-04-13 13:18:25
【问题描述】:

我想使用捆绑包“PetkoparaMultiSearchBundle”做一个搜索表单,但是当我尝试将表单放在我的树枝上时出现此错误

 {{ form_rest(filterForm) }}

这是我的 searchtype.php

   class SearchType extends AbstractType{

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

这是我的控制器

 * 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'));
}

}

我做错了什么?

【问题讨论】:

  • 您没有将$filterForm 传递给查看层,因此它在那里不可用。

标签: forms symfony controller twig bundle


【解决方案1】:

您必须将表单传递给视图。将此添加到您的控制器中。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-16
    • 2020-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    相关资源
    最近更新 更多