zoukankan      html  css  js  c++  java
  • cmstop传递什么控制器和方法---就实例化该控制器

    object顶级类
    class object

    第一级抽象类controller
    abstract class controller extends object


    第二级抽象类controller_abstract 继承controller 祖父类

    abstract class controller_abstract extends controller

    cmstop.php主程序
    设置属性public $app, $controller, $action
    用来接收并保存当前请求的模块,控制器,和方法
    实例化该对象,
    $obj = new $this->class($this);
    在cmstop.php中实例化$this.
    这次接收到的$this->controller= content
    所以.实例化的是content类,调用的方法execute()没有的时候.就到父类中找
    $response = $obj->execute();
    该execute方法在父类controller_abstract 中
    当前所有控制器.都是继承这个父类抽象类controller_abstract 中

    在父类中的$this就是类名controller_admin_content
    (实例化时的属性$this->controller= content)
    父类的$this->app就是实例化时.包含的所有有值的属性
    父类的$this->app->action就是所有属性中的action属性

    抽象父类的作用:

    if ($this->action_exists($this->app->action))//判断该当前类是否存在一个方法 存在就让他运行..call他
    用户--方法的--数组
    {
    $response = call_user_func_array(array($this, $this->app->action), $this->app->args);
    }

    这样确保.$_GET传递过来什么控制器.cmstop就实例化哪个控制器.
    并且调用该对象父类抽象类中方法,$response = $obj->execute();
    实例化时.是什么控制器.什么方法.就call他调用该控制器和方法
    call_user_func_array(array($this, $this->app->action)

    主程序中 定义公用属性
    class cmstop extends object
    public $app, $controller, $action
    接收用户请求的参数
    $this->app = 'system';
    $this->controller = 'content';
    $this->action = 'index';

    实例化$this.就是把这些属性作为参数传递给controller_admin_content类.并且触发构造方法.
    $obj = new $this->class($this);
    再传递给父类的构造方法,
    父类检查是否存在请求的方法
    if($this->action_exists($this->app->action))
    存在就call他
    $response = call_user_func_array(array($this, $this->app->action), $this->app->args);

    $obj = new $this->class($this);
    实例化时.做了2件事.
    1实例化该属性中的controller类.
    2把属性值作为参数,传递给该类的构造函数,再传递给父类的构造函数


    class controller_admin_content extends controller_abstract
    function __construct(& $app)
    {
    parent::__construct($app);
    }

  • 相关阅读:
    linux基础(六) --- 杀死包含应用名称的所有进程
    linux基础(五) ---ubuntu 修改国内源
    linux基础----vim编辑器(三)
    linux基础----vim编辑器(二)
    linux基础----vim编辑器(一)
    计算机基础----必会单词
    支付宝还可以更进一步的改造世界。
    insertAdajcentHTML
    11个触摸设备的触摸时间处理
    手机上的jQuery
  • 原文地址:https://www.cnblogs.com/bj-tony/p/5293109.html
Copyright © 2011-2022 走看看