PHP CodeIgniter paging instance and multi-condition query solution (recommended), codeigniter Paging

Source: Internet
Author: User
Tags codeigniter

PHP CodeIgniter paging instance and multi-condition query solution (recommended), codeigniter Paging

Recently, when I used the CI framework, I used the CI paging class. I used to use the front-end whole page. This time I simply used the built-in framework to record my forgetful head.

Because there are conditional filtering forms on the page, the result to be completed is that after the input conditions are entered, the input conditions can be maintained after the page Jump. I thought about the following code.

Controller code

Class Monitors extends CI_Controller {public function warning () {$ config = array (); $ config ['per _ page'] = 15; // The number of data displayed on each page $ current_page = intval ($ this-> input-> get ("per_page ")); // obtain the current page number $ status = $ this-> input-> get ("filter-status", TRUE ); $ level = $ this-> input-> get ('filter-level', TRUE); $ timestamp = $ this-> input-> get ('filter-timestamp ', TRUE); $ all = $ this-> monitors_m-> getAllData ($ current_page, $ config ['per _ Page'], $ status, $ timestamp, $ level); // The total number of returned results and specific data are displayed, add and modify the parameters as needed. $ data ['allevent'] = $ all ['content']; $ config ['total _ rows '] = $ all ['Count']; // The total number of items $ config ['num _ links'] = 3; // page number of connections $ config ['use _ page_numbers '] = TRUE; $ config ['page _ query_strings'] = TRUE; // key configuration $ config ['base _ url'] = base_url (). 'Index. php/monitors/warning? '& Filter-status = '. $ status. '& filter-level = '. $ level. '& filter-timestamp = '. $ timestamp; // key configuration $ this-> load-> library ('pagination'); // load the ci pagination class $ this-> pagination-> initialize ($ config ); $ data ['page'] = $ this-> pagination-> create_links (); // key code $ this-> load-> view ("monitors_v ", $ data );}

Key configuration parameters

$config[‘page_query_string']

If it is set to true, the url is "index. php/monitors/warning? Per_page = 20"

[Note] "per_page" is the default query string passed, but you can also use $ config ['query _ string_segment '] = 'your string' to configure

In my solution, set to TRUE, of course, TRUE is the default value, either way;

$config[‘base_url']

In the first place, it is only possible to perform conditional filtering on a certain page when it is set to the following conditions. However, after the jump, there are no conditions due to refreshing.

$config['base_url'] = base_url().'index.php/monitors/warning;

Use the following method.

$ Status = $ this-> input-> get ("filter-status", TRUE); $ level = $ this-> input-> get ('filter-level ', TRUE); $ timestamp = $ this-> input-> get ('filter-timestamp', TRUE); $ config ['base _ url'] = base_url (). 'Index. php/monitors/warning? '& Filter-status ='. $ status. '& filter-level ='. $ level. '& filter-timestamp ='. $ timestamp; // key Configuration

View page code

In one sentence, add such a sentence where you need to place the paging element. The $ page variable here is saved in the controller.$this->pagination->create_links();

<?php echo $page?>

Set paging Style

The bootstrap style is used here.

$ Config ['first _ link'] = "<"; // homepage $ config ['prev _ link'] = "<"; // Previous Page $ config ['Next _ link'] = ">"; // next page $ config ['last _ link'] = "> "; // The end page $ config ['full _ tag_open '] =' <ul class = "pagination-split"> '; $ config ['full _ tag_close '] =' </ul> '; $ config ['first _ tag_open'] = '<li> '; // start tag of the first link. $ Config ['first _ tag_close '] =' </li> '; // end tag of the first link. $ Config ['Next _ tag_open '] =' <li> '; // start tag of the next page. $ Config ['Next _ tag_close '] =' </li> '; // end tag of the next page. $ Config ['prev _ tag_open '] =' <li> '; // start tag of the previous page Link. $ Config ['prev _ tag_close '] =' </li> '; // end tag of the previous page Link. $ Config ['cur _ tag_open '] =' <li class = "active"> <a> '; $ config ['cur _ tag_close '] =' </a> </li> '; // end tag of the current page Link. $ Config ['num _ tag_open '] =' <li> '; // start tag of a digital link. $ Config ['num _ tag_close '] =' </li> '; // end tag of a digital link.

The above is a small series of PHP CodeIgniter paging instances and multi-condition query solutions. I hope to help you. If you have any questions, please leave a message, the editor will reply to you in a timely manner, and I would like to thank you for your support for the help House website!

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.