2014-03-31 155 views
1

我跟着這個link 當我運行此命令,看看Get方法是否工作得很好我的終端上顯示此錯誤錯誤415:不支持的媒體類型。415不支持的媒體類型

我要見我的源代碼:

1 - 首先我把我的配置文件:

#應用程序/配置/ config.yml sensio_framework_extra: 觀點: 註釋:假

fos_rest:

param_fetcher_listener: true 
body_listener: true 
format_listener: true 
view: 
    view_response_listener: 'force' 

2-後,我剛修好我的路由文件:

#應用程序/配置/ 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); 
    } 

回答

6

也許你需要添加一個默認格式:

# app/config/config.yml 
fos_rest: 
    routing_loader: 
     default_format: json 
+1

實體被發現,並我們返回200 OK! > ** HTTP/1.1 200 OK ** – IsmailJallouli

+1

您在響應頭中看到了什麼內容類型?你在客戶端支持這個嗎? – Dunken

相關問題