CodeIgniter 3.0 新手摺騰筆記(五) --分頁

分頁

CodeIgniter 的分頁類是一個很是簡單,而且 100% 用戶自定義的類。php

官方展現最簡單的demo數據庫

$this->load->library('pagination');
$config['base_url'] = 'http://example.com/index.php/test/page/';
$config['total_rows'] = 200;
$config['per_page'] = 20;
$this->pagination->initialize($config);//序列化
echo $this->pagination->create_links();//生成分頁導航

這裏用戶能夠進行自定義分頁,可定義的項目app

  • $config['first_link'] = '' //起始連接,好比設置成首頁
  • $config['last_link'] = '' //結束鏈接,好比尾頁
  • $config['prev_link'] = '' //上一頁
  • $config['next_link'] = '' //下一頁
  • $config['display_pages'] = FALSE; //能夠隱藏數字連接

我已設置首尾上下頁,不隱藏數字連接,樣式可能這樣的:
有數字連接的
隱藏就只顯示上下一頁,到末尾頁有首頁上一頁顯示,在首頁有下一頁尾頁顯示函數

2.2.2手冊中:this

若是你想要給每個連接添加 CSS 類,你能夠添加以下配置:
$config['anchor_class'] = "";
//添加 CSS 類url

3.0中已不同意這樣使用,3.1+版本將移除,以下spa

// Deprecated legacy support for the anchor_class option
        // Should be removed in CI 3.1+
        if (isset($params['anchor_class']))
        {
            empty($params['anchor_class']) OR $attributes['class'] = $params['anchor_class'];
            unset($params['anchor_class']);
        }

##實現
1.控制器的某個方法中加載模型,分頁主要實現由模型來實現3d

public function appoint() {
        $this->load->model('room_action');
        $array = $this->room_action->show_cate($number);

2.模型的編寫code

//分頁開始,加載分頁類
            $this->load->library('pagination');
            $count = 可由數據庫查詢相關字段得
            $pagesize = 6;
            $config['per_page'] = $pagesize;//每頁展現幾個項目
            $config['base_url'] = base_url("boardroom/appoint/cate/$number/page");//包含分頁控制器類和方法
            $config['total_rows'] = $count;//需分頁的總數據行數,我這裏從數據庫查詢到
            $config['uri_segment'] = 6;
            $offset = intval($this->uri->segment(6));//uri中分段函數,從控制器開始數,起始數字是1
            $this->pagination->initialize($config);//進行序列化
            $data['page_link'] = $this->pagination->create_links();//生成分頁按鈕
            //分頁結束
相關文章
相關標籤/搜索