TP page Jump Success and error

Source: Internet
Author: User

TP system \think\controller class built-in two jump methods success and error, for page jump prompts, and can support Ajax submissions.

$User = M (' User '); Instantiate the User object
$result = $User->add ($data); 
if ($result) {
    //Set the address of the page after success, the default return page is $_server[' http_referer ']
    $this->success (' New success ', ' user/list ');
} else {
    ///error page default jump page is to return to the previous page, usually do not need to set
    $this->error (' new failed ');
}
The first parameter of the success and error methods represents a hint, the second parameter represents a jump address, and the third parameter is a jump time (in seconds), for example:
Operation completed 3 seconds after the jump to/article/index
$this->success (' Operation completed ', '/article/index ', 3);
The operation failed 5 seconds to jump to/article/error
$this->error (' Operation failed ', '/article/error ', 5);
The jump address is optional, the default jump address for the success method is $_server["Http_referer"], and the default jump address for the error method is Javascript:history.back (-1);.
The default Wait time success method is 1 seconds and the error method is 3 seconds

Success and Error methods can all correspond to the template, the default setting is two methods corresponding to the template are:

The default error jump corresponds to the template file
' tmpl_action_error ' => think_path. ' Tpl/dispatch_jump.tpl ',
///default successfully jumps the corresponding template file
' tmpl_action_success ' => think_path. ' Tpl/dispatch_jump.tpl ',
You can also use the template files inside the project
Default error jump corresponding template file
' tmpl_action_error ' => ' public:error ';
The default successful jump to the corresponding template file
' tmpl_action_success ' => ' public:success ';
The success and Error methods automatically determine whether the current request belongs to an AJAX request and invoke the Ajaxreturn method return information If it is an AJAX request. Ajax methods below, the success and error methods encapsulate the following data back:

$data [' info ']   =   $message;//Prompt message content
$data [' status '] =   $status;  State if it is success is 1 error is 0
$data [' url ']    =   $jumpUrl;//successful or wrong jump address


redirect
The redirect method of controller class can realize the redirection function of the page.

The parameter usage of the redirect method is consistent with the use of the U function (reference URL generation section), for example:

Category operations redirected to the New module
$this->redirect (' new/category ', Array (' cate_id ' => 2), 5, ' page jump ... ');
If you simply want to redirect to a specified URL address, rather than to a module's action method, you can use the redirect function redirect directly, for example:
Redirect to the specified URL address
redirect ('/new/category/cate_id/2 ', 5, ' page jump ... ')
The first parameter of the redirect function is a URL address.

The difference between the redirect method of a controller and the redirect function is that the former is defined as a jump address with a URL rule, which is a pure URL address.

from TP manual

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.