ThinkPHP Ways to Keep Paging Search

  • 2021-07-07 06:37:51
  • OfStack

For many people who use the ThinkPHP framework, using the automatic addition, deletion and modification to check the base class should keep the search state of the result page when paging, but using the scheme in the thinkphp manual will not work.

The solution in the ThinkPHP manual is:


// Ensure query criteria when paging jumps 
foreach($map as $key=>$val) {  
$Page->parameter  .=  "$key=".urlencode($val).&;
}

It can't be used by pasting directly. After debugging, it will be found that when $map is not an array, the variable can't get the desired value. The official idea is to traverse the encapsulated search condition $map. Relatively speaking, it is better to traverse the data submitted by the form directly. Therefore, the above code can be changed:


// Ensure query criteria when paging jumps 
foreach($_GET as $key=>$val) {
//echo $key.$val;
$page->parameter  .=  "$key=".urlencode($val).&;
}

Problem solved. Of course, if your form is submitted by POST, just traverse POST.


Related articles: