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

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

WBOY
WBOYOriginal
2016-06-13 11:58:181166Durchsuche

【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 />


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

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn