【ThinkPHP】Model基类_contruct步骤中的_initialize移动到末尾会产生什么影响

WBOY
Release: 2016-06-13 11:58:18
Original
1164 people have browsed it

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

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

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


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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!