Todo controlador pai deve ter o método `get {SINGULAR} Action ($ id)` quando eu tiver um sub-recurso de vários níveis no FOS Rest Bundle
Eu tenho três controladores nomeadosBlogController
, PostController
, CommentController
esteCommentController
é sub-recurso dePostController
ePostController
sub-recurso deBlogController
.
/**
* @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
Eu definogetAction
métodos, mas eu recebo o seguinte erro:
[InvalidArgumentException]
Every parent controller must have `get{SINGULAR}Action($id)` method
where {SINGULAR} is a singular form of associated object
Editar:
Também tento alterar o nome do método paragetCommentAction($commentId)
, getPostAction($postId)
egetBlogAction
, mas não funciona.
Quando eu uso@RouteResource
anotações, o nome do método deve sergetAction($id)
, caso contrário, não funcionará.
Quando mudo pai demgh_blog_post_comment
roteador paramgh_blog
, está funcionando!