[ThinkPHP] What is the impact of moving _ initialize in the Model-based contruct method to the end? Version: ThinkPHP 3.1.3
Problem: if _ initialize () is defined in the custom Model in ThinkPHP, $ this-> cannot be used in this _ initialize to query data.
My idea is to move _ initialize in the _ contruct method of the Model base class to the end of the method. what will happen to this? Analysis!
File/ThinkPHP/Lib/Core/Model. class. in php and Model base classes _ contruct, move $ this-> _ initialize to $ this-> db... what will happen later?
/** Architecture function * obtain the instance object field check of the DB Class * @ access public * @ param string $ name model name * @ param string $ tablePrefix table prefix * @ param mixed $ connection database connection information */public function _ construct ($ name = '', $ tablePrefix = '', $ connection ='') {// model initialization $ this-> _ initialize (); // Obtain the model name if (! Empty ($ name) {if (strpos ($ name ,'. ') {// supported database name. model name definition list ($ this-> dbName, $ this-> name) = explode ('. ', $ name) ;}else {$ this-> name = $ name ;}} elseif (empty ($ this-> name )) {$ this-> name = $ this-> getModelName ();} // set the table prefix if (is_null ($ tablePrefix )) {// if the prefix is Null, no prefix $ this-> tablePrefix = '';} elseif (''! = $ TablePrefix) {$ this-> tablePrefix = $ tablePrefix;} else {$ this-> tablePrefix = $ this-> tablePrefix? $ This-> tablePrefix: C ('Db _ prefix ');} // database initialization operation // Obtain database operation objects // The current model has independent database connection information $ this-> db (0, empty ($ this-> connection )? $ Connection: $ this-> connection); // What is the impact if _ initialize is moved here? // $ This-> _ initialize ();}
Reply to discussion (solution)
The impact is: Framework running error.
The impact is: Framework running error.
Why,
Initialize is intended to initialize
While _ initialize neither has any parameters nor returns, and obviously cannot intervene in the execution of the predefined process
So it doesn't matter where it is stored.
I haven't done any operations yet. it is estimated that it is used for debugging.