0
我目前是CodeIgniter的新手,並嘗試使用codeigniter中的分頁類添加分頁。CodeIgniter - 調用一個非對象的成員函數num_rows()
控制器:
public function view_emp(){
$data['design'] = 'emp_view';
$this->load->model('user_model');
$data = $this->user_model->getall();
$total_rows = $data->num_rows();
$config['base_url'] = base_url() . 'main';
$config['total_rows'] = $total_rows;
$config['per_page'] = 10;
$this->pagination->initialize($config);
$this->view_data['pagination'] = $this->pagination->create_links();
$this->view_data['result'] = $data;
if($this->session->userdata('is_logged_in')){
$this->load->view('includes/template', $data);
}
else{
redirect('main/restricted');
}
型號:
public function getall(){
$query = $this->db->get('another_user');
return $query->result();
}
public function getall_limit($start_row, $limit){
$data = "SELECT * FROM another_user limit $start_row, $limit";
$result = $this->db->query($data);
return $result;
}
在我看來,我只是附和$分頁從我的控制器 可以在這裏誰能幫助我?我現在真的很難過。
您需要將'$這個 - > view_data'作爲參數'$ this-> load-> view()',而不是'$ data'。 – Jeemusu
是否這樣? $ this-> load-> view('includes/template',$ this-> view_data ?? – IamRey
是的,就是這樣。 – Jeemusu