thinkphp page Jump Success and Error method overview

Source: Internet
Author: User
This article mainly introduces the thinkphp page jump Success and Error method overview, the need for friends can refer to the following

Thinkphp itself provides the success method and the error method to implement the page jump function with prompt information, which can realize the effect of displaying the prompt information and jumping after adding the data. The success method is used to prompt after successful operation, the error is used to prompt after the failure of the operation, the method is exactly the same, the following is explained by the success method.
1. Success Method
The Success method syntax is as follows:
Success (message, Ajax)
The parameter description message is optional. Page tip information. Ajax is optional. Whether the Ajax method commits, the default is False.
The success method calls the Ajaxreturn method to return information if it is submitted in AJAX mode.
Success Method Examples:

Public Function Insert () {//omit some other code if ($lastInsId = $Dao->add ()) {//page jump Destination address $this->assign ("Jumpurl", "index"); This->success ("Insert Data ID: $lastInsId");} Else{header ("content-type:text/html; Charset=utf-8 "); Exit ($Dao->geterror (). ' [<ahref= "Javascript:history.back ()" > Return </a>] ');}}

Success templates
The Success method defaults to calling the success.html template under the public directory, which is tpl/public/. In this template, you receive the following template variables:
Template Variable Description:
$waitSecond jump wait time, in seconds, default success 1 seconds, error 3 seconds.
$JUMPURL jump to the destination page address, the default is $_server["Http_referer"] (the previous page of this operation).
$msgTitle the action title. Note: Assigning this variable will not take effect, success will take the _operation_success_ configuration information in the language pack, error takes _operation_fail_ configuration information.
$message page tip information.
$status operation State, the default of 1 indicates success, 0 indicates failure, and the rule can be defined by the project itself.
Success actually still calls the display () method output success.html template. Therefore, the success.html template can be modified according to the actual situation, such as adding more information hints or CSS artwork settings to meet the actual needs, the above template variables are only a few reference variables.
$JUMPURL Variable Description:
$JUMPURL variable If it does not exist, the default jump address is $_server["Http_referer"], some common jump page wording reference:

Other methods of this module such as the Index method $this->assign ("Jumpurl", "index");//With the parameter $this->assign ("Jumpurl", "index/section/". $ section);//other Modules $this->assign ("Jumpurl", "__app__/user/index");

If you want to use the U method to generate a jump destination address, you can change the URL property to the U method in success.html:

<meta http-equiv= ' Refresh ' content= ' {$waitSecond}; Url={:u ($JUMPURL)} ' >

In the operation, the assignment of the $jumpurl template variable, corresponding to the same as the U method, the details can refer to the official manual "Thinkphpu method dynamically generated URL address."
2. Error method
The error method usage is exactly the same as the Sucess method, but it is important to note that the thinkphp default configuration error method call is still the success.html template. If you need to define a template separately for the error method, you can modify the system default configuration thinkphp/common/convention.php file as follows:

' Tmpl_action_error ' = ' public:success ',//default error jump corresponding template file

or be redefined in the project configuration.
In web development, you can use the thinkphp page jump to provide the above success and error methods when you want the page to jump and display the prompt information.

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.