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 instance object field check for DB class * @access public * @param string $name model name * @param string $tablePre Fix table prefix * @param mixed $connection Database connection information */Public function __construct ($name = ", $tablePrefix =", $connection = ") {//model initialization $this->_initialize (); Gets the 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 prefix 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 operation//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 (); }
Reply to discussion (solution)
The effect is that the framework runs out of error.
The effect is that the framework runs out of error.
Why is this,
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.
Really did not do any operation, it is estimated to be used for debugging purposes.