基类:
<?php
namespace app\common\controller;
use think\Controller;
/**
* Base控制器
*/
class Base extends Controller
{
protected function _initialize()
{
echo"bae_initialize\n\r";
}
public function __construct()
{
echo"bae__construct\n\r";
}
protected function first(){
echo"first\n\r";
}
protected function second(){
echo"second\n\r";
}
protected function three(){
echo"three\n\r";
}
}
子类
总结:
1.先执行_initialize()
,如果调用父类则先执行父类后执行子类
2.再执行beforeActionList
前置方法
3.后执行__construct()
,如果调用父类则先执行父类后执行子类
4.最后执行具体路由方法
<?php
namespace app\app\controller;
use app\common\controller\AppBase;
class Me extends AppBase
{
protected $beforeActionList = [
'first',//First方法:该类中执行所有方法前执行这函数;
'second' => ['except'=>'f2,f5'],//Second方法:该类中除了f2方法外其他方法执行之前先执行这函数;
'three' =>['only'=>'f3,f4'],//Three方法:该类中只有f3方法执行前执行这函数;
];
protected function _initialize()
{
parent::_initialize();
echo"_initialize\n\r";
}
public function __construct()
{
parent::__construct();
echo"__construct\n\r";
}
public function f1(){
echo"f1\n\r";
}
public function f2(){
echo"f2\n\r";
}
public function f3(){
echo"f3\n\r";
}
}
网友评论