Thinkphp jump page Success and error template instances Tutorial _php tips

Source: Internet
Author: User
Tags php template smarty template

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.

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.