/** * 调用件事 */ private function init() { $controller = $this->load_controller(); if (method_exists($controller, ROUTE_A)) { if (preg_match('/^[_]/i', ROUTE_A)) { exit('You are visiting the action is to protect the private action'); } else { call_user_func(array($controller, ROUTE_A)); } } else { exit('Action does not exist.'); } } /** * 加载控制器 * @param string $filename * @param string $m * @return obj */ private function load_controller($filename = '', $m = '') { if (empty($filename)) $filename = ROUTE_C; if (empty($m)) $m = ROUTE_M; $filepath = PC_PATH.'modules'.DIRECTORY_SEPARATOR.$m.DIRECTORY_SEPARATOR.$filename.'.php'; if (file_exists($filepath)) { $classname = $filename; include $filepath; if ($mypath = pc_base::my_path($filepath)) { $classname = 'MY_'.$filename; include $mypath; } return new $classname; } else { exit('Controller does not exist.'); } }
以上为调用控制器的代码。
init()方法中$controller
=
$this
->load_controller();这行代码首先把整个模块类加载进来,并且初始化,并且赋值给$controller。
然后根据ROUTE_A的值来执行$controller中的ROUTE_A方法。
在显示首页的过程中根据参数'm'=>'content', 'c'=>'index', 'a'=>'init',加载了PC_PATH/modules/content/index.php文件,并执行了该类中的init()方法。
下面就要看看这个init()方法做了哪些工作。