Home > PHP Framework > ThinkPHP > Redirect in TP5 implements redirection and jump with parameters

Redirect in TP5 implements redirection and jump with parameters

藏色散人
Release: 2021-01-11 09:01:42
forward
5165 people have browsed it

The following tutorial column will introduce you to the redirect method in TP5 to implement redirection and jump with parameters. I hope it will be helpful to friends in need! Redirection

The redirect method of the \think\Controller class can implement the redirection function of the page. The parameter usage of the redirect method is consistent with the usage of the Url::build method (refer to the URL generation part). For example:

//重定向到News模块的Category操作
$this->redirect('News/category', ['cate_id' => 2]);
Copy after login

The above usage is to jump to the category operation of the News module. Re- The current URL address will be changed after orientation.

Or redirect directly to a specified external URL address, for example:

//重定向到指定的URL地址 并且使用302
$this->redirect('http://thinkphp.cn/blog/2',302);
Copy after login

Jump and redirection

can be used when redirecting Pass values ​​through session flash memory data, for example

$this->redirect('News/category', ['cate_id' => 2], 302, ['data' => 'hello']);
Copy after login
Using the redirect assistant function can also achieve more functions, for example, you can remember the current URL and then jump

redirect('News/category')->remember();
Copy after login

You need to jump to the last time When remembering the URL, use:

redirect()->restore();
Copy after login

Front-end reference

href="{:url(url,data)}
Copy after login

Back-end page jump

For example:

$this->success('批量数据添加成功', url('DataManagement/dataStatus',$data3));
Copy after login

The above is the detailed content of Redirect in TP5 implements redirection and jump with parameters. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
tp5
source:csdn.net
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