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

WBOY
풀어 주다: 2016-06-13 11:58:18
원래의
1166명이 탐색했습니다.

【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 既无参数也无返回,显然并不能干预预定流程的执行
所以放在哪里都无所谓

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!