我在分页时遇到了麻烦。我做了var_dump并且没事。返回正确的数据。我认为问题出在我的模型中。因为我使用其他型号和分页是可以的。我怎么会失踪?
<?php //pagination settings
$config['base_url'] = site_url('contato/gerenciar');
$config['total_rows'] = $this->db->count_all('msg');
$config['per_page'] = "5";
$config["uri_segment"] = 2;
$choice = $config["total_rows"] / $config["per_page"];
$config["num_links"] = floor($choice);
//config for bootstrap pagination class integration
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['first_link'] = false;
$config['last_link'] = false;
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['prev_link'] = '«';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '»';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$this->pagination->initialize($config);
$data['page'] = ($this->uri->segment(2)) ? $this->uri->segment(2) : 0;
//call the model function to get the department data
$data['deptlist'] = $this->sindico->get_msg($config["per_page"], $data['page']); var_dump($this->sindico->get_msg());
$data['pagination'] = $this->pagination->create_links();
?>
我的模式
public function get_msg()
{ $msg = $this->session->userdata('user_id');
$this->db->select('*');
$this->db->from('msg');
$this->db->join ('usuarios u', 'u.id_usu = id_user_msg');
$this->db->where('id_user_msg',$msg);
$query = $this->db->get('');
return $query->result();
}
答案 0 :(得分:1)
首先加载分页库
$this->load->library("pagination");
模特中的:
public function get_msg($limit, $offset)
{
$msg = $this->session->userdata('user_id');
$this->db->limit($limit, $offset);
$this->db->select('*');
$this->db->from('msg');
$this->db->join ('usuarios u', 'u.id_usu = id_user_msg');
$this->db->where('id_user_msg',$msg);
$query = $this->db->get('');
return $query->result();
}