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...