无论url请求什么.都可以拼接class类名.实例化.传递get参数-->给当前控制器-->传递给抽象父类-->都交给抽象父类.这个方法去处理call_user_func_array()
2016-03-25 16:23
766 查看
<?php
define('DS','/');
define('A_PATH',str_replace('\\','/',dirname(__FILE__)).DS); //01获取到主程序目录
class a {
public $app,$controller,$action,$class,$client;
public function __construct($client){
$this->client = $client;
}
public function execute(){
$this->app = $_GET['app'];
$this->controller = $_GET['controller'];
$this->action = $_GET['action'];
$this->args = $_GET;
$this->app_dir = A_PATH .'apps'.DS.$this->app.DS; //02拼接当前请求模块模块
$file = $this->app_dir.'controller'.DS.$this->controller.'.php';
$abstrfile = $this->app_dir.'abstract'.'.php';
$this->class = 'controller_'.$this->controller;
require_once($abstrfile); //03引入当前控制器抽象父类
require_once($file); //04引入当前请求控制器
$obj = new $this->class($this); //05实例化当前控制器(参数包括所有get-->传递给当前控制器--再传递给抽象父类)
$response = $obj->exec();//06统一调用父类方法.call_user_func_array()不是当前控制器类.(),无论url请求什么.都作为参数.传递调用call_user_func_array()
//call_user_func_array(array($this->app->class,$this->app->action),array($this->app->args));
//无论url请求什么.都可以拼接class类名.实例化.传递get参数-->给当前控制器-->传递给抽象父类-->都交给抽象父类.这个方法去处理call_user_func_array()
}
}
call_user_func_array( array(,指定类名,方法) ,array(给这个方法传递的参数) )
先导入php文件,主程序a.php中
实例化拼接好的.当前请求控制类.-->传递参数-->到父类-->调用父类方法call_user_func_array()-->再去调用子类
给这个方法传递参数.即使该方法,没有接收.也没报错.
$obj = new $this->class($this); -->实例化拼接好的类名后-->当前类构造方法接收存储参数-->父类也接收存储参数-->不再运行.等待其他方法调用
$response = $obj->exec(); //先到当前类.查找该方法.没有就去父类去查找
define('DS','/');
define('A_PATH',str_replace('\\','/',dirname(__FILE__)).DS); //01获取到主程序目录
class a {
public $app,$controller,$action,$class,$client;
public function __construct($client){
$this->client = $client;
}
public function execute(){
$this->app = $_GET['app'];
$this->controller = $_GET['controller'];
$this->action = $_GET['action'];
$this->args = $_GET;
$this->app_dir = A_PATH .'apps'.DS.$this->app.DS; //02拼接当前请求模块模块
$file = $this->app_dir.'controller'.DS.$this->controller.'.php';
$abstrfile = $this->app_dir.'abstract'.'.php';
$this->class = 'controller_'.$this->controller;
require_once($abstrfile); //03引入当前控制器抽象父类
require_once($file); //04引入当前请求控制器
$obj = new $this->class($this); //05实例化当前控制器(参数包括所有get-->传递给当前控制器--再传递给抽象父类)
$response = $obj->exec();//06统一调用父类方法.call_user_func_array()不是当前控制器类.(),无论url请求什么.都作为参数.传递调用call_user_func_array()
//call_user_func_array(array($this->app->class,$this->app->action),array($this->app->args));
//无论url请求什么.都可以拼接class类名.实例化.传递get参数-->给当前控制器-->传递给抽象父类-->都交给抽象父类.这个方法去处理call_user_func_array()
}
}
call_user_func_array( array(,指定类名,方法) ,array(给这个方法传递的参数) )
先导入php文件,主程序a.php中
实例化拼接好的.当前请求控制类.-->传递参数-->到父类-->调用父类方法call_user_func_array()-->再去调用子类
给这个方法传递参数.即使该方法,没有接收.也没报错.
$obj = new $this->class($this); -->实例化拼接好的类名后-->当前类构造方法接收存储参数-->父类也接收存储参数-->不再运行.等待其他方法调用
$response = $obj->exec(); //先到当前类.查找该方法.没有就去父类去查找
相关文章推荐
- Warning: ISO C++11 does not allow conversion from string literal to 'char*'
- leetcode-6 ZigZag Conversion
- 毕业设计第4-5周
- day06 web和http:Tomcat的认识,了解请求消息头和响应消息头
- HYSBZ 1012 最大数maxnumber
- Makefile经典教程(掌握这些足够)
- Hbase课程01- 和Anmy学习大数据
- Poll机制分析(转韦东山)
- swift系统学习控件篇:UIProgressView+NSTimer+UIstepper+UIAlertController
- DIV伸缩盒子box
- Mastering the game of Go with deep neural networks and tree search 中文版来了
- pycaffe 配置
- JAVA 实现多线程
- spring开发中如果service类里少了“@Transactional”,会造成dao类的数据库操作失败
- byte转换为char
- Android App的设计架构:MVC,MVP,MVVM
- 301重定向制造技巧性标题问题
- pycaffe 配置
- 2016年c#:猜数字
- Markdown,你只需要掌握这几个