我似乎碰到過Symfony 2的一個問題,我之前沒有見過(或者更多可能是我錯過了一些非常明顯的東西)。添加參數時Symfony 2路由錯誤
我有一條路線,沒有參數,完美工作,連接到控制器並顯示正確的視圖。然後我更新的路線採取一個參數,像這樣:
# Note routing
gibbo_dummy_notes_Add:
pattern: /notes/add/{notebook}
defaults: { _controller: GibboDummyBundle:Note:add, notebook: 0}
requirements:
_method: POST|GET
但是如果我現在嘗試訪問該航線notes/add/test
我得到的錯誤The controller must return a response (null given). Did you forget to add a return statement somewhere in your controller?
。如果我刪除參數,它完美的作品notes/add
。
該設置與在我的應用中使用參數的其他路由完全相同。
控制器中的操作肯定會返回響應對象。如果我在操作頂部放置die('test');
,並從URL中刪除參數,我會到達die語句並查看'test',但是如果我將該參數添加到URL中,它將顯示錯誤,因此它顯然沒有到達控制器或行動時,包括參數,但據我可以告訴路由設置正確,並沒有得到正常路由未定義的錯誤我期望看看是否有問題的網址。
進出口運行它的開發環境下,我已經試過其他瀏覽器/清除緩存等控制器NoteController看起來像
public function addAction($notebook)
{
$pageTitle = 'Note';
$form = $this->createForm(new NoteType(), null, array(
'validation_groups' => array('add')
));
$request = $this->getRequest();
if ($request->isMethod('POST')) {
$form->bind($request);
if ($form->isValid()) {
/** @var $em \Doctrine\ORM\EntityManager */
$em = $this->getDoctrine()->getManager();
/** @var $note Note */
$note = $form->getData();
$note->setNotebook();
$em->persist($note);
$em->flush();
return $this->redirect($this->generateUrl('gibbo_dummy_note_View'));
}
}
return $this->render('GibboDummyBundle:Note:new.html.twig', array(
'pageTitle' => $pageTitle,
'form_add' => $form->createView(),
'selected' => 'codebooks'
));
}
任何人都瞭解什麼,我可能是做錯了一些輕內的行動?
我的猜測是,這對奇怪的原因,另一路由匹配。您可以在探查器中查看它與路由器匹配的路線! – 2013-04-07 02:39:36
在根目錄'php app/console router:debug'中查找路由並確保它到達正確的位置 – 2013-04-07 05:19:11
感謝路由器的響應:調試顯示沒有任何異常:gibbo_codekeeper_notes_Add POST | GET/notes/add/{notebook } – 2013-04-07 08:28:57