What is the effect of moving to the end of the _initialize in the _contruct step of the "thinkphp" model base class?

Source: Internet
Author: User
What is the effect of moving the _initialize in the "thinkphp" Model base class __contruct method to the end?
Version: thinkphp 3.1.3
Question: If _initialize () is defined in the thinkphp in the custom model, the data cannot be queried in this _initialize using $this.
My idea: What is the effect of moving _initialize from the __contruct method in the model base class to the very end of the method? For analysis!

File/thinkphp/lib/core/model.class.php,model in base class __contruct $this->_initialize moved to the $this->db ... What will be the impact?

/**
* Schema function
* Get the DB Class instance object field check
* @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 ();

Get model Name
if (!empty ($name)) {
if (Strpos ($name, '. ')) {//Support database name. Definition of model name
List ($this->dbname, $this->name) = Explode ('. ', $name);
}else{
$this->name = $name;
}
}elseif (Empty ($this->name)) {
$this->name = $this->getmodelname ();
}
Set Table prefixes
if (Is_null ($tablePrefix)) {//prefix null means no prefix
$this->tableprefix = ";
}elseif ('! = $tablePrefix) {
$this->tableprefix = $tablePrefix;
}else{
$this->tableprefix = $this->tableprefix? $this->tableprefix:c (' Db_prefix ');
}

Database initialization Operations
Get database Operations Object
The current model has separate database connection information
$this->db (0,empty ($this->connection) $connection: $this->connection);


What effect would it have if we moved _initialize here?
$this->_initialize ();
}



------Solution--------------------
Initialize's intention was to initialize
_initialize has no parameters or returns, and obviously cannot interfere with the execution of the scheduled process.
So it doesn't matter where you put it.
  • Related Article

    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.