CodeIgniter pagination usage example, codeigniter example. CodeIgniter pagination usage example. codeigniter example this article describes how to use CodeIgniter pagination. For your reference, refer to the following code: CodeIgniter pagination usage example and codeigniter example.
This example describes how to use the pagination paging class of CodeIgniter. 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; // Previous Page $ config ['next _ link'] = $ this-> next_link; // next Page $ config ['last _ link'] = $ this-> last_link; // at the end of the page $ config ['total _ rows '] = $ result ['total']; // The total number of items $ 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(), );}