Home > PHP Framework > ThinkPHP > body text

How to implement jump page in thinkphp

PHPz
Release: 2023-05-29 18:55:06
forward
1913 people have browsed it

1. Use the redirect function to jump to the page

In thinkphp, you can use the redirect function to jump to other pages. The usage of this function is as follows:

public function redirect($url, $params = [], $code = 302, $withPrefix = false)
Copy after login

Among them, $url represents the page path to be jumped, $params represents the parameters that need to be passed when jumping, $code represents the HTTP status code of the jump, and $withPrefix represents whether Bring the domain name prefix. Here are some examples of using this function:

1. Jump to other controller methods

// 跳转到Home控制器的index方法
return $this->redirect('home/index');
Copy after login

2. Jump to external URL

return $this->redirect('http://www.example.com');
Copy after login

3. With parameters Jump

// 跳转到Home控制器的detail方法,并传递id参数
return $this->redirect('home/detail', ['id' => 1]);
Copy after login

2. Use the url function to generate the jump path

In addition to using the redirect function to jump to the page, you can also use the url function to generate the jump path, and then Use the redirect function to jump. The usage of the url function is as follows:

public function url($url = '', $vars = '', $suffix = true, $domain = false)
Copy after login

Among them, $url represents the URL address to be generated, $vars represents the parameters to be passed, $suffix represents whether to enable the URL suffix, and $domain represents whether to include the domain name prefix.

The following is an example of using the url function to generate a jump path:

// 生成Home控制器的index方法的URL
$url = $this->url('home/index');
return $this->redirect($url);
Copy after login

The above is the detailed content of How to implement jump page in thinkphp. For more information, please follow other related articles on the PHP Chinese website!

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