您的位置:首页 > 其它

无论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(); //先到当前类.查找该方法.没有就去父类去查找
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: