2017-08-11 14 views
1

私がしようとしたとき、私は私が(JSON/XML/HTML)形式で呼び出す取得しようとしたとき 、API呼び出しを行うためにCodeIgniterのREST_Controllerを使用して、その作業CodeIgniterの残りコントローラポスト応答

が、いここで私は結果としてXMLデータが必要ですが、それは常にXMLデータを取得できませんでした。常にJSONデータのみを表示します。あなた

protected function _detect_input_format() 
    { 
     // Get the CONTENT-TYPE value from the SERVER variable 
     $content_type = $this->input->server('CONTENT_TYPE'); 
     if (empty($content_type) === FALSE) 
     { 
      // If a semi-colon exists in the string, then explode by ; and get the value of where 
      // the current array pointer resides. This will generally be the first element of the array 
      $content_type = (strpos($content_type, ';') !== FALSE ? current(explode(';', $content_type)) : $content_type); 
      // Check all formats against the CONTENT-TYPE header 
      foreach ($this->_supported_formats as $type => $mime) 
      { 
       // $type = format e.g. csv 
       // $mime = mime type e.g. application/csv 
       // If both the mime types match, then return the format 
       if ($content_type === $mime) 
       { 
        return $type; 
       } 
      } 
     } 

:ここでは私の問題のスクリーンショット

enter image description here

私のコントローラは、ライブラリ内の法の下に使用するフォーマットの種類を検出するために、サーバー変数CONTENT_TYPEを使用して

<?php 
defined('BASEPATH') OR exit('No direct script access allowed'); 
require(APPPATH.'libraries/REST_Controller.php'); 

class User extends REST_Controller { 

    public function index_post() 
    { 
     $this->response($this->post()); 
    } 
} 
+0

スクリーンショットにformat = xmlを渡す必要があります。 – BSB

+0

[docs](https://github.com/chriskacerguis/codeigniter-restserver#content-types)を確認してください。あなたのURLは 'http:// localhost/resume/user?format = xml'のようになります。 – Tpojka

+0

うん!私もそれを試して、それは動作していません –

答えて

0

REST_Controllerisあるを共有していますPOST要求と使用の場合に独自のメソッドを記述することができます。

関連する問題