Example Analysis of Page Redirection Using redirect in ThinkPHP Framework
- 2021-09-20 19:38:45
- OfStack
In this paper, an example of ThinkPHP framework using redirect to achieve page redirection. Share it for your reference, as follows:
ThinkPHP redirect method
The ThinkPHP redirect method enables page redirection (jump). The syntax for the redirect method is as follows:
$this->redirect(string url, array params, int delay, string msg)
Parameter description:
参数 | 说明 |
url | 必须,重定向的 URL 表达式。 |
params | 可选,其它URL参数。 |
delay | 可选, 重定向延时,单位为秒。 |
msg | 可选,重定向提示信息。 |
ThinkPHP redirect Example
In the index method of the Index module, redirect to the select operation of this module:
class IndexAction extends Action{
public function index()
{
$this->redirect('select', array('status'=>1), 3, ' Page jumping ~'); //3 Seconds
}
}
1 Some common examples of redirect redirection:
// Direct redirection without delay
$this->redirect('select', array('status'=>1));
// Delay jump without parameters, output default prompt
$this->redirect('select', '', 3);
// Redirect to other module operations
$this->redirect('Public/login');
// Redirect to another group
$this->redirect('Admin-Public/login');
Hint:
1. When delaying the jump, the params parameter must be entered (it can be null), that is, delay must appear in the third bit.
2. If there is a problem with URL after jumping, because redirect method calls U method to generate the address after jumping, you can test whether the address generated by U method under 1 is correct, and then check the system configuration under 1.
For more readers interested in thinkPHP related contents, please check the topics of this site: "ThinkPHP Introduction Tutorial", "thinkPHP Template Operation Skills Summary", "ThinkPHP Common Methods Summary", "codeigniter Introduction Tutorial", "CI (CodeIgniter) Framework Advanced Tutorial", "Zend FrameWork Framework Introduction Tutorial" and "PHP Template Technology Summary".
I hope this article is helpful to the PHP programming based on ThinkPHP framework.