通过分页从codeigniter REST API(web服务)检索数据
如何使用分页从web服务检索数据?现在我可以显示数据了。但我不会分页。 我将codeigniter 3.0.6与curl库一起使用。这是我用来制作REST API的:通过分页从codeigniter REST API(web服务)检索数据,codeigniter,rest,api,curl,Codeigniter,Rest,Api,Curl,如何使用分页从web服务检索数据?现在我可以显示数据了。但我不会分页。 我将codeigniter 3.0.6与curl库一起使用。这是我用来制作REST API的: function index_get($limit = 100, $offset = 0) { $MhswID = $this->get('MhswID'); if ($MhswID == '') { $mhsw = $this->db->get('mhsw', $limit, $
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:1234@localhost/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);
}
尝试将函数名更改为index_post
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);
}
并将api url更改为
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);
}
您可以通过以下方式查看api的响应:
var_dump($this->curl->simple_get($this->API.'/mahasiswa/index'));
我认为您必须在curl中传递restapi的用户名和密码。我不知道您正在使用哪个库,它必须在RESTAPI库的文档中给出 请提供更多详细信息并显示您的代码。已编辑@parth。请检查用于插入数据的.index\u post。不管怎样,我正在使用rest服务器的这个库,分页在哪里?您可以更具体地说,哪里有问题。我已经更新了代码,检查了curl url。不,codeigniter rest不是这样工作的。我想在显示数据时使用分页。现在我可以显示100个数据,但不能使用分页。我正在使用这个图书馆