Todos los controladores principales deben tener el método `get {SINGULAR} Action ($ id)` cuando tengo un recurso secundario de varios niveles en FOS Rest Bundle
Tengo tres controladores llamadosBlogController
, PostController
, CommentController
eseCommentController
es un recurso secundario dePostController
yPostController
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
Yo definogetAction
métodos, pero obtengo el siguiente error:
[InvalidArgumentException]
Every parent controller must have `get{SINGULAR}Action($id)` method
where {SINGULAR} is a singular form of associated object
Editar:
También trato de cambiar el nombre del método agetCommentAction($commentId)
, getPostAction($postId)
ygetBlogAction
Pero no funciona.
Cuando uso@RouteResource
anotaciones, el nombre del método debe sergetAction($id)
De lo contrario, no funciona.
Cuando cambio padre demgh_blog_post_comment
enrutador amgh_blog
, ¡esta funcionando!