//=====================================
// Controller
//=====================================
public function __construct()
{
parent::__construct();
$this->load->library('myclass'); //自定函數
$this->load->helper('url'); //url helper
$this->load->library('pagination'); //載入分頁
$this->load->model('sql_base'); //載入資料庫行為
$this->myclass->is_power_check(); //確認權限
}
public function index()
{
$data['man_top'] = $this->load->view('manage/man_top','', true); // include top
$data['page_title'] = $this->config->item('bk_title');
//====================
// 分頁設定
//====================
//計算記錄總數
$config['total_rows'] = $this->sql_base->sql_result_row("select * from info");
//設置本頁路徑
$config['base_url'] = site_url()."/manage/info/index";
//設置每頁顯示記錄數
$config['per_page'] = 5;
//取目前分頁的參數(依路徑位置,例:/manage/info/index/1,第4個參數)
$config['uri_segment'] = 4;
//設置分頁導航條樣式
$config['first_link'] = '首頁';
$config['last_link'] = '末頁';
$config['next_link'] = '下一頁>';
$config['prev_link'] = '<上一頁';
//$config['page_query_string'] = TRUE; //使用參數方式
$offset=(int)$this->uri->segment(4);
//分頁初始化
$this->pagination->initialize($config);
//查詢返回陣列
$query = $this->sql_base->sql_result("select * from info limit ".$offset.",".$config['per_page']);
//分頁連結
$data['page_links'] = $this->pagination->create_links();
$data['query'] = $query;
$this->load->view('manage/info', $data); //將date帶入View
}
//=====================================
// model
//=====================================
//return sql
public function sql_result($sql){
return $this->db->query($sql);
}
//return sql total row
public function sql_result_row($sql){
$query = $this->db->query($sql);
return $query->num_rows();
}
//=====================================
// view
//=====================================
<?php
//顯示結果列表
foreach ($query->result_array() as $row){
echo $row['info_id'];
}
?>
<?php
//顯示分頁連結
echo $page_links;
?>
沒有留言:
張貼留言