This paper illustrates the realization method of the view and controller corresponding to the success and the error method of thinkphp jump page, through this example tutorial can help the reader to master the Success method and the use of the error method better.
The first is the controller, you can use the following code:
<?php
//This document is automatically generated for test run
class Indexaction extends Action
{
/**
+--------------------------- -------------------------------
* Default action
+----------------------------------------------------------
* /Public
Function index ()
{
$this->assign ("title", "Water purifier");
$User = M ("User"); Instantiate the User object
$result = $User->add ($data);
if ($result) {
//Set a successful Jump page address the default return page is $_server["Http_referer"]
$this->assign ("Jumpurl", "index");
$this->success ("New success!") ");
}
The default jump page for else{//error pages is to return to the previous page usually without setting
$this->error ("New Error!"). ");
}
$this->display ();
}
? >
success.html page Position: tpl\default\public\success.html
<!
DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >
Error page location: tpl\default\public\success.html
<!
DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >
The success and error methods have templates that can be set, the default settings are public:success and Public:error, template files can use template labels, and the following template variables can be used:
$msgTitle: Action Title
$message: Page tip Information
$status: Operation Status 1 indicates success 0 indicates failure and can be defined by the project itself.
$waitSecond: Jump Wait Time unit is wonderful
$JUMPURL: Jump page Address
the success and error methods call the Ajaxreturn method to return information if it is submitted in an AJAX manner
More interested in thinkphp related content readers can view the site topics: "thinkphp Introductory Course", "thinkphp Template Operation Skills Summary", "thinkphp Common Methods Summary", "Smarty Template Introductory Course" and "PHP template technology Summary."
I hope this article will help you with the PHP program design based on thinkphp framework.