【发布时间】:2016-05-12 21:10:08
【问题描述】:
我正在自学 Symfony。而且路由没有任何意义。
我有一个 postController 类,其中包含一些操作。最初命令行中的 crud 生成器给了我这个;
/**
* Post controller.
*
* @Route("/post")
*/
class PostController extends Controller
{
/**
* Lists all Post entities.
*
* @Route("/", name="post_index")
* @Method("GET")
*/
public function indexAction()
{
//
}
//
}
我想要实现的是从类本身中删除@Route。因此,我希望我的indexAction 成为主页,并且我班级中的所有其他操作仍以/post 开头。比如这就是我想要的;
class PostController extends Controller
{
/**
* Lists all Post entities.
*
* @Route("/", name="homepage")
* @Method("GET")
*/
public function indexAction()
{
//
}
/**
* Finds and displays a Post entity.
*
* @Route("post/{id}", name="post_show")
* @Method("GET")
*/
public function showAction(Post $post)
{
//
}
// what I want for the showAction should count for all other Actions as well
}
当我进行更改时出现错误;
找不到“GET /post/”的路由
有人可以向我解释我做错了什么以及如何解决这个问题。我不认为这是大事,可能是我看不到的小事。我想让indexAction 成为我的主要操作,即用户登录后网站打开时的操作。谢谢
【问题讨论】: