ThinkPHP empty module and empty operation, pre-operation and post-operation details (14th) _ PHP Tutorial

Source: Internet
Author: User
ThinkPHP empty module and empty operation, pre-operation and post-operation details (14 ). ThinkPHP empty module and empty operation, pre-operation and post-operation details (14) this chapter: introduction to TP empty module and empty operation, pre-operation and post-operation details 1. empty thinkPHP empty module and empty operation, pre-operation and post-operation details (14)

This topic describes TP empty modules and operations, pre-operations, and post-operations.

I. empty modules and empty operations
1. empty operation
Function _ empty ($ name ){
$ This-> show ("$ name does not exist www.Bkjia.com ");
}
2. empty module(EmptyAction. class. php file)
Class EmptyAction extends Action {
Function index (){
// $ This-> show ('

The request method does not exist!

')
$ City = M ('city ');
$ Arr = $ city-> select ();
$ This-> assign ('list', $ arr );
$ Name = MODULE_NAME; // Obtain the current module name. For more information about manual constants, see a bunch of constants similar
// Http: // localhost/thinkphp/index. php/Index/moBanXuanRan
// The module name is Index.
$ This-> display ("City: $ name ");
}
}

In the current module (controller), call methods in other modules:
// Call the method under IndexAction controller under CityAction controller
// Under new, find the corresponding method.
Class CityAction extends Action {
Public function tiaozhuan (){
$ IndexAction = new IndexAction ();
$ IndexAction-> index ();
}
}
?>

II. pre-operations and post-operations
Explanation: www.Bkjia.com
For example, I am executing the http: // localhost/thinkphp/index. php/Index/index method.
Pre-method: some logical operations performed before the index method is executed
Post method: perform some logical operations after the index method is executed.

For example, if you have a website, but you have to log on when accessing your website, you can use
Front and back operations

1. prerequisites: _ Before _ operation name
2. post operation: _ After _ operation name
Class IndexAction extends Action {
Public _ before_index (){
// Determine. if you have not logged on, you will be redirected to the homepage.
// Jump to the logon page if you do not log on
If (! Isset ($ _ SESSION ['username']) | $ _ SESSION ['username'] = ''){
$ This-> redirect ('login/index'); // jump to the index method under the Login controller
}
}
Public function index (){
$ User = M ('user ');
$ Arr = $ user-> select ();
$ This-> assign ('list', $ arr );
$ This-> display ();
}

Public _ after_index (){
$ This-> show ('this is the post-operation of the index method !! ');
}
}

Http://www.bkjia.com/PHPjc/931646.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/931646.htmlTechArticlethinkPHP empty module and empty operation, pre-operation and post-operation details (14) this chapter: introduction to TP empty module and empty operation, pre-operation and post-operation details 1. empty...

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.