我的模特
<?php
/ * *要更改此许可证标题,请在“项目属性”中选择“许可证标题”。 *要更改此模板文件,请选择“工具”|模板 *并在编辑器中打开模板。 * / class User_model扩展了CI_Model {
public function get_user($offset,$limit,$q=''){
$sql = "SELECT * FROM users WHERE 1=1 ";
if($q!=''){
$sql .=" AND name LIKE '%{$q}%' ";
}
$result['count'] = $this->db->query($sql)->num_rows();
$sql .=" LIMIT {$offset},{$limit} ";
$result['data'] = $this->db->query($sql)->result();
return $result ;
}
}
<?php
类用户扩展CI_Controller {
public function __construct(){
parent::__construct();
//load the model
// $this->load->model('user_model');
}
//load user view
public function index(){
$this->load->view('user_view');
}
//get data for datagrid
public function get_user(){
/*Default request pager params dari jeasyUI*/
$offset = isset($_POST['page']) ? intval($_POST['page']) : 1;
$limit = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
$search = isset($_POST['search']) ? $_POST['search'] : '';
$offset = ($offset-1)*$limit;
$data = $this->user_model->get_user($offset,$limit,$search);
$i = 0;
$rows = array();
foreach ($data ['data'] as $r) {
//array keys ini = attribute 'field' di view nya
$rows[$i]['first_name'] = $r->first_name;
$rows[$i]['last_name'] = $r->last_name;
$rows[$i]['phone'] = $r->phone;
$rows[$i]['email'] = $r->email;
$i++;
}
//keys total & rows wajib bagi jEasyUI
$result = array('total'=>$data['count'],'rows'=>$rows);
echo json_encode($result); //return nya json
}
}
<?php $url_data=base_url().'user/get_user';?> <?php echo $url_data;?>
<table id="dg" title="Product" class="easyui-datagrid"
style ="width:auto;height:400px"
url ='<?php echo $url_data;?>' toolbar="#toolbar"
pagination="true"
rownumbers="false"
fitColumns="true" singleSelect="true"
checkBox ="true" striped="true"
remoteSort="false"
nowrap ="false">
<thead>
<tr>
<th field="ck" checkbox="true"></th>
<th field="first_name" width="200" sortable="true">
<b>First Name</b>
</th>
<th field="last_name" width="700" sortable="true">
<b>Last Name</b>
</th>
<th field="phone" width="100" sortable="true">
<b>Phone</b>
</th>
<th field="email" width="100" sortable="true">
<b>email</b>
</th>
</tr>
</thead>
</table>
&#13;
答案 0 :(得分:0)
我对OOP没那么多,所以我可能错了。 我想你忘记在返回之前用JSON编码SQL查询的结果:
echo json_encode($result);
希望这会有所帮助。