controler
age.php
代碼: 選擇全部
<?php
class Age extends CI_Controller{
function __construct()
{
parent::__construct();
$this->load->helper('url');
}
function index()
{
//載入分頁的class
$this->load->library('pagination');
$config['base_url'] = base_url().'index.php/age/index/';
$config['total_rows'] = $this->db->count_all('ages'); //計算總共有多少筆資料
$config['per_page'] = '5'; //設定一頁幾個數量
$config['full_tag_open'] = '<p>';
$config['full_tag_close'] = '</p>';
$this->pagination->initialize($config);
//從 model 裡面的 books_model 取結果
$this->load->model('Age_model');
echo 'xxx'.$this->uri->segment(3);
$data['results'] = $this->Age_model->getdata($config['per_page'],$this->uri->segment(3));
// 3 代表目前網址中的位置 ,如 index.php/aa/bb/頁數,如果目前顯示葉樹的位置不是在第三個的話,請依據實際狀況作修改。
// 載入 HTML Table Class
$this->load->library('table');
$this->table->set_heading('ID', 'Name');
// load the view
$this->load->view('Age_view', $data);
}
}
?>
age_model.php
代碼: 選擇全部
<?php
class Age_model extends CI_Model
{
function __construct()
{
parent::__construct();
}
function getdata($num, $offset)
{
$query = $this->db->get('ages', $num, $offset);
return $query;
}
}
?>
age_view.php
代碼: 選擇全部
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href='<?php echo base_url(); ?>css/main.css' type="text/css" media="screen, projection" />
<title>CodeIgniter Pagination Tutorial</title>
</head>
<body>
<h1>Christian Books</h1>
<?php echo $this->table->generate($results); ?>
<?php echo $this->pagination->create_links(); ?>
</body>
</html>
main.css
代碼: 選擇全部
/**
* CodeIgniter Pagination Tutorial Stylesheet
*
* @author Yannick Lyn Fatt
* @email yannick@godsporch.net
*/
/*
Psalm 59:16
But I will sing of your strength, in the morning
I will sing of your love; for you are my fortress,
my refuge in times of trouble.
*/
/* basic */
body {
font: small/1.4em Verdana, Arial, Helvetica, serif;
}
/* heading */
h1 {
font-size: 150%;
}
/* tables */
table {
border-collapse: collapse;
border: 1px solid #777;
}
th, td {
padding: 10px;
border: 1px solid #777;
}
th {
text-align: left;
background-color: #abc;
}