如何使用FOSRestBundle进行POST呼叫

如何使用FOSRestBundle进行POST呼叫,rest,symfony,fosrestbundle,Rest,Symfony,Fosrestbundle,我正在尝试使用FosRestBuble设置RESTFUL web服务,但在进行POST调用时遇到一些问题,以下是我的设置: app/config/routing.yml rest: type: rest resource: "routing_rest.yml" prefix: /api app/config/routing_rest.yml Rest_User: type: rest resource: "@AppBundle/Resources/con

我正在尝试使用FosRestBuble设置RESTFUL web服务,但在进行POST调用时遇到一些问题,以下是我的设置:

app/config/routing.yml

rest:
    type: rest
    resource: "routing_rest.yml"
    prefix: /api
app/config/routing_rest.yml

Rest_User:
    type: rest
    resource: "@AppBundle/Resources/config/routing_rest.yml"
rest_application:
    type: rest
    resource:     "AppBundle:Rest"
    name_prefix:  api_
AppBundle/Resources/config/routing_rest.yml

Rest_User:
    type: rest
    resource: "@AppBundle/Resources/config/routing_rest.yml"
rest_application:
    type: rest
    resource:     "AppBundle:Rest"
    name_prefix:  api_
AppBundle/Controller/RestController.php

class RestController extends FOSRestController
{

    public function testrestAction(Request $request)
    {
        $r = [
            'is'    => 'TEST'
        ];
        return $r;
    }

    public function getArticleAction()
    {
        $r = [
            'is'    => 'GET'
        ];
        return $r;
    }

    public function postArticleAction()
    {
        $r = [
            'is'    => 'POST'
        ];
        return $r;
    }
}
我还制作了PUT和DELETE测试方法。所以当我做一些测试时

获取/api/testrest

{
    "is": "TEST"
}
GET/api/article

{
    "is": "GET"
}
No route found for "POST /api/article": Method Not Allowed (Allow: GET, HEAD) (405 Method Not Allowed)
POST/api/article

{
    "is": "GET"
}
No route found for "POST /api/article": Method Not Allowed (Allow: GET, HEAD) (405 Method Not Allowed)
PUT和DELETE也可以。我是否缺少一些配置

第二个问题:如果我在控制器文件夹中创建一个API文件夹,我会将RestController的名称空间更改为“namespace AppBundle\Controller\API”;并将“AppBundle/Resources/config/routing_rest.yml”更新为

然后我得到了这个信息:

Can't locate "AppBundle:API:Rest" controller in /var/www/ws/app/config/routing_rest.yml (which is being imported from "/var/www/ws/app/config/routing.yml").

任何需要的帮助

1-选项,运行
app/console debug:router
(或
bin/console debug:router
,如果v>2.8),列出生成的路由

2-选项,将
RouteResource
注释添加到类中(例如
文章
),将
PostArticAction
重命名为
postAction
,并检查
POST/api/文章
是否有响应


3-选项,使用
@POST
注释显式添加
文章
url,例如
/**@POST(“文章”)*/

我解决了调试路由器的问题,基本上自动生成的路由为PostArticAction方法创建/api/文章。但是,如果添加一个方法postArticlesAction,我将有两个路由(api_post_article和api_post_articles)都指向/api/articles,这对我来说没有任何意义,可能是一个bug?无论如何,谢谢你的帮助,谢谢你提醒我使用命令行进行调试。