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

Redirect in TP5 implements redirection and jump with parameters

Jan 07, 2021 pm 03:37 PM
tp5

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)