1.跨控制器调用方法
目录(E:\phpStudy\PHPTutorial\WWW\git_tp5\application\index\controller\Index.php)
public function diaoyong(){
1.使用命名空间
//调用当前模块的User控制器
$model = new \app\index\controller\User;
echo $model -> index();
echo "<hr>";
2. //使用use(use app\index\controller\User;)
$model = new User;
echo $model -> index();
echo "<hr>";
3. //使用系统方法
$model = controller("User");
echo $model -> index();
}
public function diaoyongs(){
1.使用命名空间
$model = new \app\admin\controller\Index;
echo $model -> index();
echo "<hr>";
2. //使用use(use app\admin\controller\Index as AdminIndex;)
$model = new AdminIndex();
echo $model -> index();
echo "<hr>";
3. //使用系统方法
#系统方法一般在(E:\phpStudy\PHPTutorial\WWW\git_tp5\thinkphp\helper.php)
$model = controller("admin/Index");
echo $model -> index();
}
12.调用方法
1.调用当前控制器的方法
public function fangfa(){
//调用当前控制器的test方法
//使用面向对象的技术
echo $this -> test();
echo "<hr>";
echo self::test();
echo "<hr>";
echo Index::test();
echo "<hr>";
//使用系统方法
echo action("test");
}
2.调用User控制器下的index方法
//调用其他控制器的方法
public function fangfas(){
1.使用命名空间
$model = new \app\index\controller\User;
echo $model -> index();
echo "<hr>";
2.使用系统方法
echo action('User/index');
}
3.调用后台模块下Index控制器index方法
public function fangfass(){
1.命名空间
$model = new \app\admin\controller\Index;
echo $model -> index();
echo "<hr>";
2.使用系统方法
echo action("admin/Index/index");
}
13.主要分析TP执行流程
1.入口文件(E:\phpStudy\PHPTutorial\WWW\git_tp5\public\index.php)
作用:
1)定义目常量
2)加载框架引导目录
2.加载框架引导文件(E:\phpStudy\PHPTutorial\WWW\git_tp5\thinkphp\base.php)
作用:
1)引导基础文件
2)对应用进行运转
3.加载框架的基础引导文件(E:\phpStudy\PHPTutorial\WWW\git_tp5\thinkphp\base.php)
1)加载系统常量
2)引入loader类(E:\phpStudy\PHPTutorial\WWW\git_tp5\thinkphp\library\think\loader.php)自动加载器
3)引入环境变量
4)注册自动环境加载机制
5)注册异常处理机制E:\phpStudy\PHPTutorial\WWW\git_tp5\thinkphp\library\think\Error.php)
6)加载惯例配置(E:\phpStudy\PHPTutorial\WWW\git_tp5\thinkphp\convention.php)
4.运行应用(E:\phpStudy\PHPTutorial\WWW\git_tp5\thinkphp\library\think\App.php)下的run方法;
1)第一步:加载当前控制器中initialize()方法
2)第二步:加载当前控制器中init()方法
1.加载各种配置文件
2.加载公共文件
3.加载语言包
3)第三步设置时区
4)加载当前控制器 routeCheck()方法 检测路由缓存
5)调用控制器中的config()方法
1.根据用户的请求进行分发处理
6)第六步:根据不同的请求类型加载对应方法(module)
加载到对应的控制器和方法
5.响应输出
用户看到的所有界面就显示出来了