Home >PHP Framework >ThinkPHP >thinkphp modify jump
When using the ThinkPHP framework, we often need to perform jump operations. By default, ThinkPHP's jump function jumps to the specified URL address, for example:
$this->redirect('http://www.example.com');
But sometimes, we need to perform some additional operations or modify the default jump method when jumping. This article will introduce how to modify the ThinkPHP jump method.
In ThinkPHP, there are two ways of jump function: redirect and success/error.
The redirect function is the default jump function provided by the ThinkPHP framework, which is used to jump to the specified URL address.
$this->redirect('http://www.example.com');
The first parameter of the redirect function is the URL address to be jumped. If you want to jump to a method of the current controller, you can use the U function to generate the URL address:
$this->redirect(U('index'));
The jump delay time can be set through the second parameter:
$this->redirect(U('index'), 3, '跳转中...');
The third parameter of the redirect function is the prompt information. If this parameter is set, the prompt information will be output before the jump.
The redirect function is a function in the thinkController class. In other classes, you can use $this->redirect() to jump.
The success and error functions are used to jump to the success and error pages that come with the framework. Their usage is as follows:
$this->success('操作成功', U('index')); $this->error('操作失败', U('index'));
The first parameter is the prompt information, and the second parameter is the jump address. If the jump address is not set, it will jump to the last accessed address by default.
By default, the ThinkPHP framework jump function uses the Header function to jump, that is, jump directly to the specified URL address. But in some cases, we need to change the jumping method, for example, we need to perform certain operations before jumping, or need to pass some parameters when jumping, etc.
ThinkPHP framework provides a redirect method for modifying the jump method. Before jumping, perform certain operations and pass parameters before jumping.
$this->redirect('jump', array('id'=>1), 2, '跳转中...');
The above code will call the jump method:
public function jump($id){ // do something $this->redirect('http://www.example.com'); }
We can perform some operations in the jump method, such as querying the database, setting up Session, etc. Then perform the jump operation again when jumping.
The first parameter of the redirect method is the method to be jumped, the second parameter is the parameter to be passed, the third parameter is the jump time, and the fourth parameter is the prompt information when jumping. .
In the ThinkPHP framework, the jump function is very commonly used and very flexible. By modifying the jump method, we can perform some operations before the jump to make the jump more intelligent. The above is my summary of ThinkPHP modification jumps.
The above is the detailed content of thinkphp modify jump. For more information, please follow other related articles on the PHP Chinese website!