【发布时间】:2014-05-10 21:57:39
【问题描述】:
我关注了这个link 当我运行此命令以查看 Get 方法是否正常工作时,我的终端中显示此错误 ERROR 415: Unsupported Media Type.
我要去看看我的源代码:
1- 首先我设置我的配置文件:
#app/config/config.yml sensio_framework_extra: 看法: 注释:假
fos_rest:
param_fetcher_listener: true body_listener: true format_listener: true view: view_response_listener: 'force'
2- 在我修复路由文件之后:
#app/config/routing.yml
minn_ads_api: resource: "@MinnAdsAPIBundle/Resources/config/routing.yml" type: rest
3- 我还在 *AdsAPIBundle 中设置了路由文件:*
#AdsAPIBundle/Resources/config/routing.yml brend: type: rest resource: Minn\AdsAPIBundle\Controller\BrendController
4- 在我的 AdsAPIBundle 下,我只需插入函数:
#src/BundleApi/Controller/BrendController.php
/**
* @Rest\View
* @Rest\Get("/api/brend/{id}", requirements={"id" = "\d+"}, defaults={"id" = 1})
*/
public function getAction($id) {
$repo = $this->getDoctrine()->
getManager()->
getRepository("MinnAdsBundle:Brend");
$brend = $repo->find($id);
return array('brend' => $brend);
}
【问题讨论】:
标签: symfony fosrestbundle