Home  >  Article  >  Backend Development  >  【ThinkPHP】Model基类contruct方法中的_initialize移动到末尾会产生什么影响?

【ThinkPHP】Model基类contruct方法中的_initialize移动到末尾会产生什么影响?

WBOY
WBOYOriginal
2016-06-23 13:56:151064browse

版本:ThinkPHP 3.1.3
问题:ThinkPHP 中如果在自定义Model里面定义了 _initialize(),那么在这个 _initialize 中无法使用 $this->来查询数据。
我的想法:将Model基类中 __contruct 方法中的 _initialize 移动到该方法的最末尾,这样会产生什么影响?求分析!

文件/ThinkPHP/Lib/Core/Model.class.php,Model 基类__contruct 中的 $this->_initialize 移动到 $this->db... 后会有何影响?

    /**     * 架构函数     * 取得DB类的实例对象 字段检查     * @access public     * @param string $name 模型名称     * @param string $tablePrefix 表前缀     * @param mixed $connection 数据库连接信息     */    public function __construct($name='',$tablePrefix='',$connection='') {        // 模型初始化        $this->_initialize();        // 获取模型名称        if(!empty($name)) {            if(strpos($name,'.')) { // 支持 数据库名.模型名的 定义                list($this->dbName,$this->name) = explode('.',$name);            }else{                $this->name   =  $name;            }        }elseif(empty($this->name)){            $this->name =   $this->getModelName();        }        // 设置表前缀        if(is_null($tablePrefix)) {// 前缀为Null表示没有前缀            $this->tablePrefix = '';        }elseif('' != $tablePrefix) {            $this->tablePrefix = $tablePrefix;        }else{            $this->tablePrefix = $this->tablePrefix?$this->tablePrefix:C('DB_PREFIX');        }        // 数据库初始化操作        // 获取数据库操作对象        // 当前模型有独立的数据库连接信息        $this->db(0,empty($this->connection)?$connection:$this->connection);        //假如把_initialize移动到这里会产生什么影响?        //$this->_initialize();    }


回复讨论(解决方案)

产生的影响就是:框架运行出错。

产生的影响就是:框架运行出错。



为什么会这样,

initialize 的本意是初始化
而 _initialize 既无参数也无返回,显然并不能干预预定流程的执行
所以放在哪里都无所谓

还真是没做任何操作,估计是用来做调试用得。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn