|
本帖最后由 tlerbao 于 2012-5-28 17:58 编辑
控制器里面
PHP复制代码
function newslist()
{
$classid = $this->uri->segment(3);
$total_rows = $this->news_mdl->get_news_num($classid);
//分页开始
$this->load->library('pagination'); //载入分也类
$config['base_url'] = site_url('news/newslist/'.$classid);
$config['total_rows'] = $total_rows; //记录总数
$config['per_page'] = 3; //每页数
$config['uri_segment'] = 4;
$config['use_page_numbers'] = TRUE;
$config['first_link'] = '首页';
$config['last_link'] = '末页';
$config['next_link'] = '下一页';
$config['prev_link'] = '上一页';
$this->pagination->initialize($config); //初始化分页
$data['newsnav'] = $this->news_mdl->get_newsnav();
$data['newslist'] = $this->news_mdl->get_news_list($classid,$this->uri->segment(4,0),$config['per_page']);
$this->load->view('news/list',$data);
}
复制代码
模型里面
PHP复制代码
function get_news_num($classid) //获取栏目新闻总数
{
$query = $this->db->where('news_class',$classid)->get('dili_u_m_news');
return $query->num_rows();
}
function get_news_list($classid,$offset,$limit) //获取新闻列表分页
{
$query = $this->db->where('news_class',$classid)->order_by('id','DESC')->limit($offset,$limit)->get('dili_u_m_news');
return $query->result();
}
复制代码
|
|