<?php
namespace Acme\TaskBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Acme\TaskBundle\Entity\Task;
use Symfony\Component\HttpFoundation\Request;
class DefaultController extends Controller
{
public function indexAction($name)
{
return $this->render('AcmeTaskBundle:Default:index.html.twig', array('name' => $name));
}
public function newAction(Request $request)
{
// just setup a fresh $task object (remove the dummy data)
$task = new Task();
$task->setTask('Write a blog post');
$task->setDueDate(new \DateTime('tomorrow'));
$form = $this->createFormBuilder($task)
->add('task', 'text')
->add('dueDate', 'date')
->getForm();
if ($request->isMethod('POST'))
{
$form->bind($request);
if ($form->isValid())
{
// perform some action, such as saving the task to the database
return $this->redirect($this->generateUrl('task_success'));
}
}
}
}
它在這裏說:控制器必須返回一個響應(null給出)。你忘了在控制器的某個地方添加一個return語句嗎? 任何人都可以幫助我在此它在這裏說:控制器必須返回一個響應(null給出)。你忘了在控制器的某個地方添加一個return語句嗎?
[錯誤沒有響應的Symfony2](http://stackoverflow.com/questions/15766887/error-no-response-symfony2) –
如果($請求 - > isMethod( 'POST'))的可能重複 { $ form-> bind($ request); if($ form-> isValid()) { //執行一些操作,例如將任務保存到數據庫 return $ this-> redirect($ this-> generateUrl('task_success')); \t} \t \t} }返回$這 - >渲染( 'AcmeTaskBundle:默認:new.html.twig',陣列( '形式'=> $形式 - > CreateView的(), \t \t \t)) ; } – raffryan