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.