您好,登錄后才能下訂單哦!
這篇文章給大家介紹CodeIgniter中如何使用pagination分頁類,內容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
controller控制器(application/controller/page.php文件):
public function index() { $this->load->model ( 'home_model' , '' , TRUE); $config= array(); $config['per_page'] = $this->per_page; //每頁顯示的數據數 $current_page = intval($this->input->get_post('per_page',true)); //獲取當前分頁頁碼數 //page還原 if(0 == $current_page) { $current_page = 1; } $offset = ($current_page - 1 ) * $config['per_page']; //設置偏移量 限定 數據查詢 起始位置(從 $offset 條開始) $result = $this->home_model->index($offset,$config['per_page'],$order='id desc'); $config['base_url'] = $this->config->item('base_url').'admin/home/index?'; $config['first_link'] = $this->first_link;//首頁 $config['prev_link'] = $this->prev_link;//上一頁 $config['next_link'] = $this->next_link;//下一頁 $config['last_link'] = $this->last_link;//尾頁 $config['total_rows'] = $result['total'];//總條數 $config['num_links'] = 3;//頁碼連接數 $config['use_page_numbers'] = TRUE; $config['page_query_string'] = TRUE; $this->load->library('pagination');//加載ci pagination類 $this->pagination->initialize($config); $result = array( 'list' => $result['list'], 'total' => $result['total'], 'current_page' => $current_page, 'per_page' => $config['per_page'], 'page' => $this->pagination->create_links(), ); $this->load->view ( 'admin/home' , $result ); }
model模型(application/model/home_model.php文件):
public function index($offset,$num,$order='id desc') { $query = $this->db->query( "SELECT Name_cn,Mall_type,create_time FROM smzdm_mall WHERE Is_deleted = 0 order by {$order} limit {$offset},{$num}"); return array( 'total' => $this->db->count_all('smzdm_mall',array('Is_deleted'=>'0')), 'list' => $query->result(), ); }
關于CodeIgniter中如何使用pagination分頁類就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。