This article mainly introduces how to use pagination in the CodeIgniter paging class, and analyzes the basic configuration and usage skills of pagination in the CodeIgniter framework based on the example, for more information about how to use pagination in the CodeIgniter paging class, see the example in this article. We will share this with you for your reference. The details are as follows:
Controller (application/controller/page. php file ):
Public function index () {$ this-> load-> model ('Home _ model', '', TRUE); $ config = array (); $ config ['per _ page'] = $ this-> per_page; // The number of data displayed on each page $ current_page = intval ($ this-> input-> get_post ('per _ page', true )); // Obtain the current page number. // restore the page if (0 = $ current_page) {$ current_page = 1;} $ offset = ($ current_page-1) * $ config ['per _ page']; // sets the offset to limit the start position of the data query (starting from $ offset) $ result = $ this-> home_model-> index ($ Fset, $ config ['per _ page'], $ order = 'Id desc '); $ config ['base _ url'] = $ this-> config-> item ('base _ url '). 'admin/home/index? '; $ Config ['first _ link'] = $ this-> first_link; // homepage $ config ['prev _ link'] = $ this-> prev_link; // $ config ['last _ link'] = $ this-> last_link; // The End Page $ config ['total _ rows '] = $ result ['total']; // total number of lines $ config ['Num _ links '] = 3; // page number of connections $ config ['use _ page_numbers'] = TRUE; $ config ['page _ query_string '] = TRUE; $ this-> load-> library ('pagination '); // load the ci pagination class $ 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 file ):
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(), );}