2016-08-26 2 views
1

ページングを使用してWebサービスからデータを取得する方法は?今のところ私はデータを表示することができます。しかし、私は改ページを行うことはできません。 私はcurlライブラリでcodeigniter 3.0.6を使用しています。これは私がREST APIを作るために使用するものである:codeigniterからデータを取得するページ番号付きのREST API(Webサービス)

function index_get($limit = 100, $offset = 0) { 
    $MhswID = $this->get('MhswID'); 
    if ($MhswID == '') { 
     $mhsw = $this->db->get('mhsw', $limit, $offset)->result(); 
    } else { 
     $this->db->where('MhswID', $MhswID); 
     $mhsw = $this->db->get('mhsw', $limit, $offset)->result(); 
    } 
    $this->response($mhsw, 200); 
} 

し、データを取得するために、これは次のとおりです。

function __construct() { 
    parent::__construct(); 
    $this->API="http://admin:[email protected]/ci3_rest/index.php"; 
} 

// menampilkan data mahasiswa 
function index($limit = "", $offset = ""){ 
    $data['mahasiswa'] = json_decode($this->curl->simple_get($this->API.'/mahasiswa')); 
    $this->load->view('welcome_message',$data); 
} 
+0

詳細を入力してコードを表示してください。 – parth

+0

編集済み@parth。チェックしてください。 – heruprambadi

答えて

1

function index_post() { 
    $limit = $this->post('limit'); 
    $offset = $this->post('offset'); 
    $MhswID = $this->post('MhswID'); 
    if ($MhswID == '') { 
     $mhsw = $this->db->get('mhsw', $limit, $offset)->result(); 
    } else { 
     $this->db->where('MhswID', $MhswID); 
     $mhsw = $this->db->get('mhsw', $limit, $offset)->result(); 
    } 
    $this->response($mhsw, 200); 
} 

をindex_postとAPIを変更するには、関数名を変更してくださいURL to

function index($limit = 100, $offset = 0){ 
    $data['mahasiswa'] = json_decode($this->curl->simple_get($this->API.'/mahasiswa/index/', array('limit' => $limit, 'offset' => $offset)); 
    $this->load->view('welcome_message',$data); 
} 

あなたは

var_dump($this->curl->simple_get($this->API.'/mahasiswa/index')); 

により、APIの応答を表示することができますし、私はあなたがカールにREST APIのユーザー名とパスワードを渡す必要がありますと思います。どのライブラリを使用しているのか分かりません。そのライブラリはREST APIライブラリのドキュメントで指定する必要があります。

+0

index_postはデータの挿入に使用されます。私はこのライブラリをrestサーバーに使用しています。https://github.com/chriskacerguis/codeigniter-restserver – heruprambadi

+0

とにかく、ページネーションはどこですか? – heruprambadi

+0

問題が発生している場所を具体的に特定できますか?私はコードを更新し、カールのURLを確認してください。 – parth

関連する問題