Home > PHP Framework > ThinkPHP > body text

Solve thinkphp pagination garbled problem

Release: 2020-06-02 09:06:37
forward
2515 people have browsed it

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;
}
Copy after login

2. Modify the final generated url

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

$url=U('',$parameter);
Copy after login

to:

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

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!

Related labels:
source:zixuephp
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template