我正在尝试动态化我通过互联网找到的服务器端的数据表(用于首选项 http://mbahcoding.com/tutorial/php/codeigniter/codeigniter-simple-server-side-datatable-example.html),因为在本教程中,表和列是固定的。
控制器
public function __construct()
{
parent::__construct();
$this->load->model('CrudModel');
$this->load->model('AccountModel');
$this->load->model('customers_model','customers');
}
public function ajax_list()
{
// $list = $this->customers->get_datatables();
$list = $this->AccountModel->get_datatables('customers'); //my table name
$data = array();
$no = $_POST['start'];
foreach ($list as $customers) {
$no++;
$row = array();
$row[] = $no;
$row[] = $customers->FirstName;
$row[] = $customers->LastName;
$row[] = $customers->phone;
$row[] = $customers->address;
$row[] = $customers->city;
$row[] = $customers->country;
$data[] = $row;
}
$output = array(
"draw" => $_POST['draw'],
"recordsTotal" => $this->customers->count_all(),
"recordsFiltered" => $this->customers->count_filtered(),
"data" => $data,
);
//output to json format
echo json_encode($output);
}
问题是$this->客户->count_all()和count_filtered()从何而来?
$this->customers->count_all() and count_filtered()
函数来自您的模型
叫
$this->load->model('customers_model','customers');
你应该在其中检查你的模型,你可以找到这个函数
function count_filtered()
{
$this->_get_datatables_query();
$query = $this->db->get();
return $query->num_rows();
}
public function count_all()
{
$this->db->from($this->table);
return $this->db->count_all_results();
}