|
控制器books.php
<?php
class Books extends Controller
{
function Books()
{
parent::Controller();
$this->load->helper('url');
$this->load->database();
}
function index()
{
$this->load->library('pagination');
$config['total_rows']=$this->db->count_all('ci1');
$config['per_page']=2;
$config['uri_segment']=3;
$config['full_tag_open']='<p>';
$config['full_tag_close']='</p>';
$this->pagination->initialize($config);
$this->load->model('books_model');
$data['results']=$this->books_model->get_books($config['per_page'],$this->uri->segment(3));
$this->load->library('table');
$this->table->set_heading('ID','Title','Author','Description');
$this->load->view('books_view',$data);
}
}
?>
模型层
books_model.php
<?php
class books_model extends Model
{
function books_model()
{
parent::Model();
}
function get_books($num,$offset)
{
$query=$this->db->get('ci1',$num,$offset);
return $query;
}
}
?>
视图
books_view.php
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>CI 分页</title>
</head>
<h1>分页</h1>
<?php echo $this->table->generate($results); ?>
<?php echo $this->pagination->create_links(); ?>
</html>
运行结果。。
|
|