Home > PHP Framework > ThinkPHP > How to solve the problem of garbled characters in thinkphp pagination

How to solve the problem of garbled characters in thinkphp pagination

WJ
Release: 2020-06-02 17:09:15
forward
2984 people have browsed it

How to solve the problem of garbled characters in thinkphp pagination

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 In the URL, after the URL is encrypted, it will be garbled when passed for the second time. If we use "?" and "&" to separate the 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 the thinkphp paging class file Page.class.php to replace the parameter separator in the URL. The function 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

Self-study PHP blog
2. Modify the final generated url
In line 99 of the Page.class.php file, replace the original

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

is modified to:

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

After these two steps of modification, the problem of thinkphp paging garbled characters can be solved.

Related references:thinkphp tutorial

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

Related labels:
source:segmentfault.com
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