ThinkPHPredirect page redirection usage details and instances

Source: Internet
Author: User
The ThinkPHPredirect method can be used to redirect pages. The redirect Method syntax is as follows: ThinkPHP redirect Method

The ThinkPHP redirect method enables page redirection (redirection. Redirect
The method syntax is as follows:




  1. $ This-> redirect (string url, array params, int delay, string msg)

Parameter description:
The url must be a redirected URL expression.
Params
Optional. other URL parameters.
Optional. redirection latency, in seconds.
Msg (optional) redirection prompt.
ThinkPHP redirect
Instance

In the Index method of the index module, select operations to redirect to this module:




  1. Class IndexAction extends Action {
  2. Public function index (){
  3. $ This-> redirect ('select', array ('status' => 1), 3, 'page jump in progress ~ ');
  4. }
  5. }

URL obtained after redirection
Possible: http://www.phplo.com/index.php/Index/select/status/1

Because this method calls U
Function to generate the actual URL redirection address. Therefore, the URL after redirection may vary depending on the configuration:

The index. php file is hidden.
Of
Http://www.phplo.com/Index/select/status/1
The index. php file is hidden.
And set the pseudo-static
Http://www.phplo.com/Index/select/status/1.html

Some common
Redirect Redirection example:




  1. // Direct redirection without delay

  2. $ This-> redirect ('select', array ('status' => 1 ));
  3. // Delayed jump without parameters. the default prompt is displayed.
  4. $ This-> redirect ('select', '', 3 );
  5. // Redirect to other modules
  6. $ This-> redirect ('public/login ');
  7. // Redirect to another group
  8. $ This-> redirect ('admin-Public/login ');

Tip:

When the jump is delayed, you must enter params
The parameter (which can be null), that is, the delay parameter must appear on the 3rd bits.
If there is a problem with the URL after the jump, the redirect method calls U
Method to generate the jump address. at this time, you can test whether the address generated by the U method is correct, and then check the system configuration.
If you do not want to use the U method to generate a jump address, you can directly use PHP
Header function or $ this-> redirect prototype function redirect (string url, int delay, string
Msg). Note that the url is an absolute address. for details, see The PHP header function.

Redirect redirection and success/error
Jump differences

Redirect is the PHP header redirection used, while success/error is the html meta used.
Http-equiv = 'refresh' property jump.
Redirect does not have a template page, and the output prompt information is directly output by echo in the function, while
Success/error has a template.
Both redirect and success/error can redirect pages, but only redirect
There can be no latency redirection, depending on the specific situation.

Read more

ThinkPHP U method: dynamically generate URL addresses
PHP
Header
ThinkPHP rewrite: Use the rewrite rules of the. htaccess file to remove
Index. php
ThinkPHP pseudo-static

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.