[ThinkPHP] What is the impact of moving _ initialize in the Model-based contruct method to the end?

Source: Internet
Author: User
[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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.