当我运行此命令以查看Get方法是否正常工作时,我按照此链接检测到我的终端ERROR 415:不支持的媒体类型中显示此错误.
我要看看我的源代码:
1-首先我设置我的配置文件:
#app/config/config.yml sensio_framework_extra:view:annotations:false
fos_rest:
Run Code Online (Sandbox Code Playgroud)param_fetcher_listener: true body_listener: true format_listener: true view: view_response_listener: 'force'
2-我刚修好路由文件后:
#应用程序/配置/ routing.yml中
Run Code Online (Sandbox Code Playgroud)minn_ads_api: resource: "@MinnAdsAPIBundle/Resources/config/routing.yml" type: rest
3-我还在我的*AdsAPIBundle中设置了路由文件:*
Run Code Online (Sandbox Code Playgroud)#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);
}
Run Code Online (Sandbox Code Playgroud)