Home  >  Article  >  PHP Framework  >  Solve thinkphp pagination garbled problem

Solve thinkphp pagination garbled problem

尚
forward
2020-06-02 09:06:372493browse

Solve thinkphp pagination garbled problem

thinkphp’s built-in paging class has bugs. For example, when we search for keywords, the keywords are Chinese. When we click paging for the second time, the characters will be garbled and cannot be displayed normally. The page number we need. This article provides a solution to this problem.

The problem of garbled characters is due to problems in constructing urls in the thinkphp paging class. Thinkphp's paging urls use "/" to separate parameters. When passing data to the url, through the url Encryption will cause garbled characters when passed the second time. However, if we use "?" and "&" to separate parameters, this problem will not occur.

So the content to be modified is thinkphp’s paging class file: /ThinkPHP/Extend/Library/ORG/Util/Page.class.php file.

The specific modified code is:

1. Add a custom function at the end of thinkphp paging class file Page.class.php to replace the parameter separator symbol in the url. Function The content is as follows:

private function clin_page_url($parameter){
  $url = U('');
  $url = str_replace('.html', '?', $url);
  foreach ($parameter as $key => $value) {
     $url .= $key.'='.$value.'&';
  }
  $url = substr($url, 0,-1);
  return $url;
}

2. Modify the final generated url

In line 99 of the Page.class.php file, change the original

$url=U('',$parameter);

to:

$url=$this->clin_page_url($parameter); // 生成标准的url

After these two steps of modification, you can solve the problem of garbled paging in thinkphp.

Recommended tutorial: "TP5"

The above is the detailed content of Solve thinkphp pagination garbled problem. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:zixuephp. If there is any infringement, please contact admin@php.cn delete