This article mainly introduces ThinkPHP jump page success and error template instance tutorials, which can help beginners to further familiarize themselves with the page jump process of ThinkPHP, for more information about how to implement the view and controller corresponding to the success and error methods on ThinkPHP jump pages, this example helps you better understand the use of the success and error methods.
First, you can use the following code in the controller:
<? Php // This document is automatically generated. it is only for testing and running class IndexAction extends Action {/** + ------------------------------------------------------ * default operation + functions */public function index () {$ this-> assign ("title", "water purifier"); $ User = M ("User "); // instantiate the User object $ result = $ User-> add ($ data); if ($ result) {// after successful settings, the default return page is $ _ SERVER ["HTTP_REFERER"] $ this-> assign ("jumpUrl", "index "); $ This-> success ("added successfully! ");} Else {// The default jump page of the error page is to return to the previous page. Generally, you do not need to set $ this-> error (" New error! ") ;}$ This-> display () ;}}?>
Success.html: Tpl \ default \ Public \ success.html
Successful message
Success message prompt |
{$ Message} Title information processed successfully: {$ msgTitle} Custom success message: {$ message} Custom error message: {$ error} Jump page path: {$ jumpUrl} Stay Time: {$ waitSecond} 2 seconds later, return to the specified page! If the browser cannot jump, click here. |
Error page location: Tpl \ default \ Public \ success.html
Successful message
Error message prompt |
{$ Message} Title information processed successfully: {$ msgTitle} Custom success message: {$ message} Custom error message: {$ error} Jump page path: {$ jumpUrl} Stay Time: {$ waitSecond} 2 seconds later, return to the specified page! If the browser cannot jump, click here. |
The Success and error methods both have corresponding templates and can be set. the default settings are Public: success and Public: error. template labels can be used for template files, you can also use the following template variables:
$ MsgTitle: Operation title
$ Message: page prompt information
$ Status: Operation status 1 indicates success. 0 indicates failure. you can also define rules for the project.
$ WaitSecond: the unit of the jump wait time is wonderful.
$ JumpUrl: Jump page address
If the request is submitted in AJAX mode, the success and error methods call the ajaxReturn method to return information.