ThinkPHP page jump success and error methods overview. ThinkPHP itself provides the success and error methods for page jump with prompt information, which can display prompt information and jump effect after adding data. The success method is used for ThinkPHP itself. the success method and error method are used to implement page jump with prompt information. after adding data, the system displays prompt information and jumps. The success method is used for the prompt after the operation is successful, and the error method is used for the prompt after the operation fails. The two methods are the same. the success method is described below.
1. success method
The success method syntax is as follows:
Success (message, ajax)
Parameter description message is optional. Page prompt information. Ajax is optional. Whether to submit data in AJAX mode. the default value is false.
If the request is submitted in AJAX mode, the success method calls the ajaxReturn method to return information.
Success method example:
Public function insert () {// omit some other code if ($ lastInsId = $ Dao-> add ()) {// the target URL for page jump $ this-> assign ("jumpUrl", "index"); $ this-> success ("insert data id: $ lastInsId ");} else {header ("Content-Type: text/html; charset = utf-8"); exit ($ Dao-> getError (). '[return]') ;}}
Success Template
The success method calls the success.html template under TPL/Public/by default. In this template, the following template variables are received:
Template variable description:
$ WaitSecond jump wait time, in seconds. the default value is success 1 second and error 3 seconds.
$ JumpUrl: Jump to the target page address. the default value is $ _ SERVER ["HTTP_REFERER"] (the previous page in this tutorial ).
$ MsgTitle operation title. Note: The value assigned to this variable does not take effect. success takes the _ OPERATION_SUCCESS _ configuration information in the language pack, and the _ OPERATION_FAIL _ configuration information for error.
$ Message page prompt information.
$ Status indicates the Operation status. the default value is 1, indicating that the operation is successful. The value 0 indicates that the operation fails. you can also define rules for the project.
Success still calls the display () outputs output success.html template. For this reason, you can modify the success.html template, such as adding more information prompts or making CSS artist settings to meet actual needs. the preceding template variables are just some reference variables.
$ JumpUrl variable description:
If the $ jumpUrl variable does not exist, the default jump address is $ _ SERVER ["HTTP_REFERER"]. for some common jump page writing methods, refer:
// Other methods of this module, such as the index method $ this-> assign ("jumpUrl", "index"); // add the parameter $ this-> assign ("jumpUrl ", "index/section /". $ section); // Other modules $ this-> assign ("jumpUrl", "/index. php/User/index ");
If you want to use the uessto generate a destination address, you can change the URL attribute to the U method format in success.html:
In the operation, the value of the $ jumpUrl template variable must be changed to the same as that of the U method. for details, refer to the official manual ThinkPHPU method to dynamically generate a URL address.
2. error method
The usage of the error method is exactly the same as that of the sucess method. However, you must note that the ThinkPHP connector still uses the success.html template to configure errorworkflow. If you need to define a template for the error method separately, you can modify the system default configuration ThinkPHP/Common/convention. php file as follows:
'Tmpl _ ACTION_ERROR '=> 'public: success', // default error jumps to the corresponding template file
Or re-define in the project configuration.
In Web development, you can directly use the above success and error methods provided by ThinkPHP page jump when page jump is required and prompt information is displayed. If you do not need to prompt but directly redirect the page, refer to the ThinkPHP redirect redirection section in the manual.
Bytes. The success method is used...