think\Model::__construct PHP Method

__construct() public method

架构函数
public __construct ( array | object $data = [] )
$data array | object 数据
    public function __construct($data = [])
    {
        if (is_object($data)) {
            $this->data = get_object_vars($data);
        } else {
            $this->data = $data;
        }
        // 当前类名
        $this->class = get_class($this);
        if (empty($this->name)) {
            // 当前模型名
            $name = str_replace('\\', '/', $this->class);
            $this->name = basename($name);
            if (Config::get('class_suffix')) {
                $suffix = basename(dirname($name));
                $this->name = substr($this->name, 0, -strlen($suffix));
            }
        }
        if (is_null($this->autoWriteTimestamp)) {
            // 自动写入时间戳
            $this->autoWriteTimestamp = $this->db()->getConfig('auto_timestamp');
        }
        // 执行初始化操作
        $this->initialize();
    }

Usage Example

Esempio n. 1
0
 /**
  * 构造函数
  * @param string $name 模型名称
  * @param string $tablePrefix 表前缀
  * @param mixed $connection 数据库连接信息
  */
 public function __construct($name = '', $tablePrefix = '', $connection = '')
 {
     /* 设置默认的表前缀 */
     $this->tablePrefix = C('DB_PREFIX') . 'document_';
     /* 执行构造方法 */
     parent::__construct($name, $tablePrefix, $connection);
 }
All Usage Examples Of think\Model::__construct