我正在使用Mac OSX El Capitan上的Symfony 3.2.0开发应用程序,我可以查看http://127.0.0.1:8000/category/create但是当我转到/ category / edit / 1时,我收到404错误:
No route found for "GET /category/edit/1"
这是我的CategoryController.php:
<?php
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
class CategoryController extends Controller
{
/**
* @Route("/categories", name="category_list")
*/
public function indexAction(Request $request)
{
// replace this example code with whatever you need
return $this->render('category/index.html.twig', [
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
]);
}
/**
* @Route("/category/create", name="category_create")
*/
public function createAction(Request $request)
{
// replace this example code with whatever you need
return $this->render('category/create.html.twig', [
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
]);
}
/**
* @Route("/category/edit/{id}", name="category_edit")
*/
public function editAction(Request $request)
{
// replace this example code with whatever you need
return $this->render('category/edit.html.twig', [
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
]);
}
/**
* @Route("/category/delete/{id}", name="category_delete")
*/
public function deleteAction(Request $request)
{
}
}
我在类别文件夹中创建了edit.html.twig文件。
ldco2016@DCortes-MacBook-Pro-3 ~/Projects/eventcalendar $ php bin/console debug:router --env=prod [ruby-2.2.1]
----------------- -------- -------- ------ -----------------------
Name Method Scheme Host Path
----------------- -------- -------- ------ -----------------------
category_list ANY ANY ANY /categories
category_create ANY ANY ANY /category/create
category_delete ANY ANY ANY /category/delete/{id}
homepage ANY ANY ANY /
event_list ANY ANY ANY /events
event_create ANY ANY ANY /event/create
category_edit ANY ANY ANY /event/edit/{id}
event_delete ANY ANY ANY /event/delete/{id}
----------------- -------- -------- ------ -----------------------
答案 0 :(得分:2)
调试此方法的一个好方法是运行此命令:
php bin/console debug:router --env=prod
这将显示所有路径及其路径,并且(如本例所示)查看它们是否被其他一些同名路由覆盖。