


Solution to the problem that the first and last pages of the CI paging class are not displayed, ci paging_PHP tutorial
Jul 12, 2016 am 08:55 AMThe solution to the problem that the first and last pages of the CI paging class are not displayed, ci paging
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",總數(shù),頁顯示數(shù)量); //分頁
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.
Articles you may be interested in:
- Codeigniter (CI) framework paging function and related knowledge
- CodeIgniter paging class pagination usage example
- codeigniter implementation Get paging method
- Codeigniter framework implements the method of getting paging data and total number of items
- Example of paging class that passed the test in codeigniter
- CodeIgniter assisted third-party class library third_party Usage analysis
- Detailed explanation of CodeIgniter extended core class examples
- php implementation of shopping cart class that imitates CodeIgniter
- Codeigniter shopping cart class cannot add Chinese solutions
- Use CodeIgniter’s class library to upload images
- Use configuration classes to define Codeigniter global variables
- Instructions on how to use codeigniter’s own database class
- In-depth analysis of CodeIgniter image processing class

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Common problems and solutions for PHP variable scope include: 1. The global variable cannot be accessed within the function, and it needs to be passed in using the global keyword or parameter; 2. The static variable is declared with static, and it is only initialized once and the value is maintained between multiple calls; 3. Hyperglobal variables such as $_GET and $_POST can be used directly in any scope, but you need to pay attention to safe filtering; 4. Anonymous functions need to introduce parent scope variables through the use keyword, and when modifying external variables, you need to pass a reference. Mastering these rules can help avoid errors and improve code stability.

To safely handle PHP file uploads, you need to verify the source and type, control the file name and path, set server restrictions, and process media files twice. 1. Verify the upload source to prevent CSRF through token and detect the real MIME type through finfo_file using whitelist control; 2. Rename the file to a random string and determine the extension to store it in a non-Web directory according to the detection type; 3. PHP configuration limits the upload size and temporary directory Nginx/Apache prohibits access to the upload directory; 4. The GD library resaves the pictures to clear potential malicious data.

There are three common methods for PHP comment code: 1. Use // or # to block one line of code, and it is recommended to use //; 2. Use /.../ to wrap code blocks with multiple lines, which cannot be nested but can be crossed; 3. Combination skills comments such as using /if(){}/ to control logic blocks, or to improve efficiency with editor shortcut keys, you should pay attention to closing symbols and avoid nesting when using them.

AgeneratorinPHPisamemory-efficientwaytoiterateoverlargedatasetsbyyieldingvaluesoneatatimeinsteadofreturningthemallatonce.1.Generatorsusetheyieldkeywordtoproducevaluesondemand,reducingmemoryusage.2.Theyareusefulforhandlingbigloops,readinglargefiles,or

The key to writing PHP comments is to clarify the purpose and specifications. Comments should explain "why" rather than "what was done", avoiding redundancy or too simplicity. 1. Use a unified format, such as docblock (/*/) for class and method descriptions to improve readability and tool compatibility; 2. Emphasize the reasons behind the logic, such as why JS jumps need to be output manually; 3. Add an overview description before complex code, describe the process in steps, and help understand the overall idea; 4. Use TODO and FIXME rationally to mark to-do items and problems to facilitate subsequent tracking and collaboration. Good annotations can reduce communication costs and improve code maintenance efficiency.

TolearnPHPeffectively,startbysettingupalocalserverenvironmentusingtoolslikeXAMPPandacodeeditorlikeVSCode.1)InstallXAMPPforApache,MySQL,andPHP.2)Useacodeeditorforsyntaxsupport.3)TestyoursetupwithasimplePHPfile.Next,learnPHPbasicsincludingvariables,ech

In PHP, you can use square brackets or curly braces to obtain string specific index characters, but square brackets are recommended; the index starts from 0, and the access outside the range returns a null value and cannot be assigned a value; mb_substr is required to handle multi-byte characters. For example: $str="hello";echo$str[0]; output h; and Chinese characters such as mb_substr($str,1,1) need to obtain the correct result; in actual applications, the length of the string should be checked before looping, dynamic strings need to be verified for validity, and multilingual projects recommend using multi-byte security functions uniformly.

ToinstallPHPquickly,useXAMPPonWindowsorHomebrewonmacOS.1.OnWindows,downloadandinstallXAMPP,selectcomponents,startApache,andplacefilesinhtdocs.2.Alternatively,manuallyinstallPHPfromphp.netandsetupaserverlikeApache.3.OnmacOS,installHomebrew,thenrun'bre
