CodeIgniter Pagination Example _php instance of a page-class using method

Source: Internet
Author: User
Tags getting started with php
The example of this article describes how to use the CodeIgniter page class pagination. Share to everyone for your reference, as follows:

Controller controllers (application/controller/page.php files):

Public Function Index () {$this->load->model (' Home_model ', ' ", TRUE);    $config = Array (); $config [' per_page '] = $this->per_page; The number of data displayed per page $current _page = intval ($this->input->get_post (' Per_page ', true));    Gets the number of page pages currently paged//page restore if (0 = = $current _page) {$current _page = 1; } $offset = ($current _page-1) * $config [' per_page ']; Set offset qualification data query start position (starting with $offset bar) $result = $this->home_model->index ($offset, $config [' Per_page '], er = ' id des    C '); $config [' base_url '] = $this->config->item (' Base_url '). '    Admin/home/index? '; $config [' first_link '] = $this->first_link;//home $config [' prev_link '] = $this->prev_link;//prev $config [' Next_link '] = $this->next_link;//next $config [' last_link '] = $this->last_link;//last $config [' Total_rows '    ] = $result [' Total '];//number $config [' num_links '] = 3;//number of connections $config [' use_page_numbers '] = TRUE;    $config [' page_query_string '] = TRUE; $thisLoad->library (' pagination ');//Load CI pagination class $this->pagination->initialize ($config); $result = Array (' list ' = = $result [' list '], ' total ' and ' = ' $result [' total '], ' current_page ' =    $current _page, ' per_page ' = $config [' per_page '], ' page ' and $this->pagination->create_links (),    ); $this->load->view (' Admin/home ', $result);}

Model models (application/model/home_model.php file):

Public Function Index ($offset, $num, er = ' id desc ') {    $query = $this->db->query ("Select Name_cn,mall_type, Create_time from smzdm_mall WHERE is_deleted = 0 ORDER by {er} limit {$offset},{$num} ");    Return Array (        ' total ' = $this->db->count_all (' Smzdm_mall ', Array (' is_deleted ' = ' 0 ') '),        ' list ' = > $query->result (),    );}

More interested in CodeIgniter related content readers can view this site topic: "CodeIgniter Introductory Tutorial", "CI (codeigniter) Framework Advanced Tutorial", "PHP date and Time usage summary", "PHP object-oriented Programming introduction Tutorial", " PHP String Usage Summary, "Getting Started with Php+mysql database operations" and "PHP Common Database Operations Skills Summary"

It is hoped that this article is helpful to the PHP program design based on CodeIgniter framework.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.