thinkPHP empty module and empty operation, pre-operation and post-operation detailed introduction (14)
This chapter: Introducing TP empty modules and empty operations, pre-operations and post-operations. Detailed introduction
1. Empty modules and empty operations
1. No 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('
This request method does not exist!
')
$city=M('City');
$arr=$city->select();
$this->assign('list',$arr);
$name=MODULE_NAME; //Get the current module name, the manual constant reference has a bunch of similar constants
//http://localhost/thinkphp/index.php/Index/moBanXuanRan
//The module name is: Index
$this->display("City:$name");
}
}
Under the current module (controller), call methods under other modules:
//Call the method under the IndexAction controller under the CityAction controller
//Just download new and find the corresponding method later
class CityAction extends Action{
public function tiaozhuan(){
$indexAction = new IndexAction();
$indexAction->index();
}
}
?>
2. Pre-operation and post-operation
Explanation: www.Bkjia.com
For example: I am currently executing the http://localhost/thinkphp/index.php/Index/index index method
Pre-method: some logical operations performed before executing the index method
Post-method: some logical operations performed after executing the index method
Example: For example, if you have a website now, but you have to log in to access your website, you can use
Pre and post operations
1. Pre-operation: _before_operation name
2. Post operation : _after_ operation name
class IndexAction extends Action{
public _before_index(){
//Judge, if you are not logged in, jump to the homepage
//If you are not logged in, jump to the login page
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 Detailed introduction to empty modules and empty operations, pre-operations and post-operations (14) This chapter: Introduction TP empty module and empty operation, pre-operation and post-operation detailed introduction 1. Empty...