CI Pagination Class Home page, end of resolution _php instances not shown

Source: Internet
Author: User
Tags getting started with php
This article describes the CI pagination class first page, the end of the solution is not displayed. Share to everyone for your reference, as follows:

Read the manual said, every time you have to write it again some $config, you can create a new file under the Config folder, consider the next, config this folder system will automatically load, that is, no matter what page you visit this folder all the information will be loaded, so, To write in this file, you need to write a method, so that even if the load is not loaded is not related. I did not follow the instructions in the manual.

My idea: Since we are writing in the framework of CI, and each controller will introduce the parent class Ci_controller This class, all I created in this class A method, the name page code is as follows:

Public Function page ($url, $total, $pre, $status =true) {  $this->load->library (' pagination ');  $config [' base_url '] = $url;  $config [' total_rows '] = $total;  $config [' per_page '] = $pre;  $config [' page_query_string '] = $status;  $config [' first_link '] = ' first ';//home  $config [' first_tag_open '] = ';  $config [' first_tag_close '] = ';  $config [' last_link '] = ' last ';//End  $config [' last_tag_open '] = ';  $config [' last_tag_close '] = ';  $this->pagination->initialize ($config);  $page _list = $this->pagination->create_links ();  return $page _list;}

Parameter description, $url: The address at which the paging is currently required. $total: Total. $pre: The number of displays per page $status by default is true to &page=1 the page in a way that is displayed in a way that is PAGE/1 if modified to false.

Then use the following directly in your controller

$page _list = $this->page ("Http://XXX.XXXX.com/XXX/XXX", total, number of pages displayed);//pagination

This is both.

Tips: The system comes with the value of the parameter is not called the page but pre_page like, forget, because the parameter is too long, you are in the root directory-"system-->libraries--" pagination.php found var $query _string_segment = "formal parameter"; Here you can modify the page.

Test is found if the above, the first page and the last page does not show the reason: Your data is too small, paging data at least 4 pages before the first page of the word, but we can modify, here I set to 3 pages to display, then also go to this pagination.php file found

var $num _links = 2; Here the default is 2 is the fourth page to display, modified to 1, note that the minimum can only be modified to 1, if you want to display in any case you need to modify the code to find this code:

if ($this->first_link!== FALSE and $this->cur_page > ($this->num_links + 1))

The modification will remove both and after the, because the and followed by the qualification, the following: $this->cur_page represents the current page, $this->num_links is to show when the display, and other code here does not say, Find out for yourself what to ask $num_links cannot be set to 0

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.