model层
public function get_content($start,$num){
$sql = "SELECT * FROM content limit $start,$num";//$start=>每一页第一条数据所对应的索引;$num=>对应的每一页固定显示的条数
$query = $this->db->query($sql);
return $query->result();
}
controllers层
public function index()
{
$num = 2;
$page = $this->uri->segment(3);
if(empty($page)){
$start = 0;
}else{
$start = $page;
}
$data[‘results‘] = $this->voice_model->get_content($start, $num);//根据$start(每一页索引的开始值)和$num(每一页要显示的数目)去数据库取
$total = $this->db->count_all(‘content‘);//计算数据库中的表news的数据总条数
$config[‘base_url‘] = base_url().‘index.php/content_control/index‘;//配置url
$config[‘total_rows‘] = $total;//总条数
$config[‘per_page‘] = $num; //第一页显示的数目
$this->pagination->initialize($config); //调用ci自带的initialize函数
$this->load->view(‘content.html‘,$data);//将数组$data的内容传递给视图页knowledge.php
}
views层
<?php echo $this->pagination->create_links();?>