如何使用分页从Web服务检索数据?现在我能够显示数据。但我不能做分页。 我正在使用带有curl库的codeigniter 3.0.6。这就是我用来制作REST API的方法:
#topbar {
width: 1080px;
margin: 0 auto;
height: 40px;
}
body {
margin: 0;
padding: 0;
font-family: Helmet, Freesans, Helvetica, Arial, sans-serif;
;
}
#logo {
margin-top: 8px;
float: left;
margin-right: 8px;
}
.border-part {
float: left;
height: 100%;
border-left: 1px #CCCCCC solid;
}
#logo-image {
width: 20px;
margin: 12px;
float: left;
}
.signin-text {
margin: 14px;
font-size: 90%;
font-weight: bold;
float: left;
}
#dash-image {
padding-left: 50px;
float: left;
height: 40px;
}
#bell {
margin: 8px;
height: 28px;
float: left;
}
.stuff-section {
font-weight: bold;
font-size: 90%;
padding: 13px 15px 0 15px;
height: 27px;
}
.seacher-border {
float: left;
height: 100%;
border-left: 1px #CCCCCC solid;
margin-left: 20px;
}
#search-box {
margin: 10px;
font-weight: bold;
background-color: #E4E4E4;
font-size: 14px;
border: none;
height: 24px;
float: left;
}
#search-pic {
position: relative;
right: 10px;
top: 10px;
height: 25px;
}
#second-bar {
background-color: #BB1919;
width: 100%;
height: 80px;
}
#newsbar {
width: 1080px;
margin: 0 auto;
background-color: blue;
}
h1 {
padding: 0;
margin: 0;
float;
}
这是检索数据:
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);
}
答案 0 :(得分:1)
尝试将函数名称更改为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中传递REST api的用户名和密码。我不知道你使用的是哪个库,它必须在REST api库的文档中给出。