Symfony2 未定义变量:handleRequest
Symfony2 Undefined variable: handleRequest
我正在尝试在 Symfony2 中开发一个基本形式并让 handleRequests
工作。但是我遇到错误 undefined variable handleRequest
并且似乎无法解决问题![=15=]
这是我的控制器
<?php
namespace James\workBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use James\workBundle\Entity\Task;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class DefaultController extends Controller
{
public function newAction(Request $request)
{
$task = new Task();
$task->setTask('Write a blog post');
$task->setDueDate(new \DateTime('tomorrow'));
$form = $this->createFormBuilder($task)
->add('task','text')
->add('dueDate','date')
->add('save','submit')
->getForm();
$form = $handleRequest($request);
if ($form->isValid())
{
exit('form was valid');
return $this->redirect($this->generateUrl('task_new'));
}
// $request = $this->getRequest(
//if ($request->getMethod() == 'POST'){
// $form->bindRequest($request);
//if ($form->isValid())
//{
//return $this->redirect($this->generateUrl('task_success'));
// }
// }
return $this->render('JamesworkBundle:Default:index.html.twig',
array(
'form'=> $form->createView(),
));
}
}
这是我的树枝
{% extends 'base.html.twig' %}
{% block body %}
<div class="container">
{{form(form)}}
</div>
{% endblock %}
这是我的路由
task_new:
path: /
defaults: { _controller: JamesworkBundle:Default:new }
task_success:
path: /success
defaults: { _controller: JamesworkBundle:Default:success }
您输错了这一行:
$form = $handleRequest($request);
handleRequest
是 $form
的一个方法,它处理 POST
请求。
应该是:
$form->handleRequest($request);
我正在尝试在 Symfony2 中开发一个基本形式并让 handleRequests
工作。但是我遇到错误 undefined variable handleRequest
并且似乎无法解决问题![=15=]
这是我的控制器
<?php
namespace James\workBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use James\workBundle\Entity\Task;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class DefaultController extends Controller
{
public function newAction(Request $request)
{
$task = new Task();
$task->setTask('Write a blog post');
$task->setDueDate(new \DateTime('tomorrow'));
$form = $this->createFormBuilder($task)
->add('task','text')
->add('dueDate','date')
->add('save','submit')
->getForm();
$form = $handleRequest($request);
if ($form->isValid())
{
exit('form was valid');
return $this->redirect($this->generateUrl('task_new'));
}
// $request = $this->getRequest(
//if ($request->getMethod() == 'POST'){
// $form->bindRequest($request);
//if ($form->isValid())
//{
//return $this->redirect($this->generateUrl('task_success'));
// }
// }
return $this->render('JamesworkBundle:Default:index.html.twig',
array(
'form'=> $form->createView(),
));
}
}
这是我的树枝
{% extends 'base.html.twig' %}
{% block body %}
<div class="container">
{{form(form)}}
</div>
{% endblock %}
这是我的路由
task_new:
path: /
defaults: { _controller: JamesworkBundle:Default:new }
task_success:
path: /success
defaults: { _controller: JamesworkBundle:Default:success }
您输错了这一行:
$form = $handleRequest($request);
handleRequest
是 $form
的一个方法,它处理 POST
请求。
应该是:
$form->handleRequest($request);