Parameter property assignment value
For example, to retrieve a user table with a status of 1 (Status=1) and an electronic containing 163 of users, when submitting a form (note that the form is submitted by GET mode), the resulting URL address is roughly the following:
http://www.5idev.com/index.php/Index/search/status/1/email/163
The main code in the search operation is as follows:
Public Function Search () { $Dao = M ("User"); Constructs the query condition $condition [' status '] = $_get[' status ']; $condition [' email '] = array (' Like ', "%". $_get[' email '). " %"); Total count $count = $Dao->where ($condition)->count (); Import the paging class import ("ORG. Util.page "); Instantiate the paging class $p = new page ($count, ten); Get query Parameters $map [' status '] = $_get[' status ']; $map [' email '] = $_get[' email ']; foreach ($map as $key = + $val) { $p->parameter. = "$key =". UrlEncode ($val). " & "; } Pagination Display output $page = $p->show (); Current page data query $list = $Dao->where ($condition)->order (' uid ASC ')->limit ($p->firstrow. ', '. $p listRows)->select (); Assignment Value $this->assign (' page ', $page); $this->assign (' list ', $list); $this->display ();}
In the page's paging link, you can see that the address (for example, page 2nd) is:
http://www.5idev.com/index.php/Index/search/status/1/email/163?status=1&email=163&p=2
You can see that the status=1&email=163 condition that needs to be retrieved is already included in the paging link. Of course, the actual parsed address should be:
http://www.5idev.com/index.php/Index/search/status/1/email/163/p/2/
This is because the thinkphp paging class is not perfect for handling URLs. To improve on this, see the thinkphp custom paging style and URL.
Incoming parameter parameter
The key to paging with query criteria is to set the parameter property value for the paging class . In addition to assigning values to the Parameter property in the previous example, the parameter parameter can be passed in directly when the class is instantiated, and the results are consistent:
$parameter = ' status= '. UrlEncode ($_get[' status '). ' &email= '. UrlEncode ($_get[' email ');//Add parameter parameter when instantiating a paging class $p = new Page ($count, ten, $parameter);//pagination display output $page = $p ->show ();
Tips
The above example is only used to describe the use of the query condition in the paging, so the retrieved keywords are not processed securely. In actual use, before the query, the user input keywords to do security aspects of processing.