【发布时间】:2015-10-12 18:16:47
【问题描述】:
我有三个控制器,分别命名为BlogController、PostController、CommentController,CommentController 是PostController 的子资源,PostController 是BlogController 的子资源。
/**
* @Rest\RouteResource("blog", pluralize=false)
*/
class BlogController extends FOSRestController
{
public function getAction($blogUri)
{
...
}
}
/**
* @Rest\RouteResource("post", pluralize=false)
*/
class PostController extends FOSRestController
{
public function getAction($postId)
{
...
}
}
/**
* @Rest\RouteResource("comment", pluralize=false)
*/
class CommentController extends FOSRestController
{
public function getAction($commentId)
{
...
}
}
routing.yml
mgh_blog:
resource: MGH\BlogBundle\Controller\BlogController
type: rest
mgh_blog_post:
resource: MGH\BlogBundle\Controller\PostController
type: rest
parent: mgh_blog
mgh_blog_post_comment:
resource: MGH\PostBundle\Controller\CommentController
type: rest
parent: mgh_blog_post
我定义了getAction 方法,但出现以下错误:
[InvalidArgumentException]
Every parent controller must have `get{SINGULAR}Action($id)` method
where {SINGULAR} is a singular form of associated object
编辑:
我也尝试将方法名称更改为getCommentAction($commentId)、getPostAction($postId) 和getBlogAction,但没有用。
当我使用@RouteResource注解时,方法名必须是getAction($id),否则不起作用。
当我将 mgh_blog_post_comment 路由器的父级更改为 mgh_blog 时,它正在工作!
【问题讨论】:
-
能否请您发布命令
app/console debug:router的输出? -
@giosh94mhz
debug:routerdumpInvalidArgumentException错误 -
这与您在网络服务器上遇到的错误相同。您需要注释掉有问题的路线,然后运行该命令。这样,我可以看到哪条路线可能会干扰(如果有的话)
标签: symfony fosrestbundle symfony-2.7