The example in this article describes the solution to the problem that the first and last pages of the CI paging class are not displayed. Share it with everyone for your reference, the details are as follows:
After reading the manual, it said that you have to write the $config again every time. You can create a new file and put it under the config folder. After thinking about it, the system will automatically load the config folder, which means that no matter what All the information in the folder of whatever page you visit will be loaded. Therefore, if you want to write in this file, you need to write a method, so that it does not matter even if it is loaded but not loaded. I didn't follow what the manual said.
My idea: Since we are writing under the CI framework, and each controller will introduce the parent class CI_Controller, I created a method in this class with the name page code 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';//首页 $config['first_tag_open'] = ''; $config['first_tag_close'] = ''; $config['last_link'] = 'Last';//尾页 $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 that currently needs to be used for paging. $total: total number. $pre: The number displayed on each page. $status is true by default. The page is passed in the form of &page=1. If it is changed to false, it will be displayed in the form of page/1.
Then use it directly in your controller as follows
$page_list = $this->page("http://XXX.XXXX.com/XXX/XXX",总数,页显示数量); //分页
That’s fine.
tips: The value-passing parameter that comes with the system is not called page but pre_page. I forgot, because the parameter is too long, you are in the root directory--"system-->libraries- -》In Pagination.php, find var $query_string_segment ="Formal parameter"; just modify the page here.
The test is to find out that if you follow the above writing method, the reason why the home page and last page are not displayed: your data volume is too small, and the word home page will not appear until at least 4 pages of paginated data, but we can modify it, here I If it is set to 3 pages, then go to the pagination.php file and find
var $num_links = 2; the default here is 2, which is only displayed on the fourth page. Change it to 1. Note that the minimum value here can only be changed to 1. If you want to display it under any circumstances, you need to modify the code. Find This code:
if ($this->first_link !== FALSE AND $this->cur_page > ($this->num_links + 1))
Modify and remove everything after and, because after and is the limiting condition, explain: $this->cur_page represents the current page, $this->num_links is when it will be displayed, and There are other codes that I won’t explain here. You can look it up yourself and ask why $num_links cannot be set to 0
Readers who are interested in more CodeIgniter related content can check out the special topics of this site: "codeigniter introductory tutorial", "CI (CodeIgniter) framework advanced tutorial", "php date and time usage summary", "php object-oriented program" Design introductory tutorial", "php string (string) usage summary", "php mysql database operation introductory tutorial" and "php common database operation skills summary"
I hope this article will be helpful to everyone’s PHP program design based on the CodeIgniter framework.