初始化操作
在控制器任何方法执行前都执行某方法
_initialize方法就是对__construct的封装,如果添加了__construct方法 那_initialize方法则不执行。
class IndexController extends Controller {
public function __construct(){
echo 'this is constrcut<br>';
}
public function _initialize(){
echo 'this is _initialize ';
}
public function index($name='cc'){
echo 'index';
}
}
前置 后置操作
_initialize方法时调用所有操作方法之前都会执行前置和后置操作方法。
前置和后置操作是针对于某个方法的_before和_after
class IndexController extends Controller {
public function _before_index(){
echo 'before<br>';
}
public function _after_index(){
echo '<br>after';
}
public function index($name='cc'){
echo $name;
}
}