使用提交按钮进行Symfony2路由

时间:2015-07-03 20:16:32

标签: symfony

我正在尝试使用Symfony2文档从一个页面(管理员页面)路由到另一个页面(ListQuestions),仍然无法使用提交按钮进行...

管理员控制器:

public function newAction(Request $request)
{
    $entity = new Admin();
    $form   = $this->createCreateForm($entity);

    $request = $this->getRequest();
    if($request->getMethod()== 'POST')
    {
        $form->bindRequest($request);
        if($form->isValid())
        {
            return $this->redirect($this->'PRIPRIBundle:ListQuestions:index.html.twig');
        }
        }
            return $this->redirect('PRIPRIBundle:Admin:index.html.twig'.
             array(
        'entity' => $entity,
        'form'   => $form->createView(),
    ));
    }

routing.yml:

_index:
    pattern:  index
    defaults: { _controller: PRIPRIBundle:Admin:index }

index.html.twig:

    

    name="input" action="" method="post">

    <input type="submit" name="submit" value="Submit">

1 个答案:

答案 0 :(得分:1)

您关注的文档是什么?这里有一堆错误。

  • 如何重定向到模板文件?
  • bindRequest方法已被弃用至少一整年。
  • 这个createCreateForm方法是什么?
  • 您的路由与您的操作不匹配PRIPRIBundle:管理员:索引 - &gt; newAction。

我认为您应该仔细查看最新文档https://symfony.com/doc/current/book/forms.html(现在是v2.7)。