【发布时间】:2014-07-06 22:57:38
【问题描述】:
我有一个EventApiController 类,如下所示
Class EventApiController
{
public function getAction($event_id)
{
// ...
}
public function putAction($event_id)
{
// ...
}
}
使用 Friends of Symfony 捆绑包的路线生成,我希望路线看起来像
CalendarBundle_get_events [GET] /api/v1/events/{event_id}.{_format}
CalendarBundle_put_events [PUT] /api/v1/events/{event_id}.{_format}
但是,Route 生成器似乎会自动将 post fix /api 添加到所有路由,因此路由看起来像这样。而且文档也没有将其显示为预期的行为。
CalendarBundle_get_events_api [GET] /api/v1/events/{event_id}/api.{_format}
CalendarBundle_put_events_api [PUT] /api/v1/events/{event_id}/api.{_format}
有谁知道如何从生成的链接中删除 /api 后期修复?我正在使用 FOS/ResutBundle 1.3.1 版
我用于 fos_rest 的 config.yml
fos_rest:
routing_loader:
default_format: json
include_format: true
view:
view_response_listener: true
而且我的 Bundle 中的 routing.yml 看起来像这样
event_api:
type: rest
resource: "@CalendarBundle/Controller/EventsApiController.php"
prefix: /api/v1
name_prefix: CalendarBundle_
【问题讨论】:
-
请将您的
fos_rest配置和相关路由部分添加到问题中。 -
能否请您使用应用程序中的真实路由更新
[GET|PUT]路由,以便我们可以看到它们与配置的匹配程度,即app/console router:debug | grep CalendarBundle_的输出。目前event_api的prefix路由不在其中...还是您发布了错误的路由配置? -
我无法找到任何证据表明将
_api添加到路由名称或将/api添加到 FOSRestBundle 代码中的 url,即 RouteLoader。对我来说,似乎有另一个包负责这种行为。您是否以某种方式额外注释了控制器类/动作? -
不,控制器操作只是一个简单的 getAction(),感谢您的帮助,尽管我会进一步调查,并在找到结果时发布结果。
-
您是否添加了
implements ClassResourceInterface和/或添加了@RouteResource("Event")注释?见implicit resource name definition
标签: symfony routing fosrestbundle