Example #1
0
 /**
  * 构造函数
  *
  * @param string $name 模型名称
  * @param array $dbConfig 数据库配置
  */
 public function __construct($name = __CLASS__, $dbConfig = '')
 {
     // 模型初始化
     $this->_initialize();
     // 获取模型名称
     $this->_name = $name;
     //使用默认配置
     if (empty($dbConfig)) {
         $dbConfig = (require _CONFIG_ . 'db.php');
     }
     $this->_dao = Leb_Dao_Abstract::getInstance($dbConfig);
     if (isset($dbConfig['debug'])) {
         self::$debug = $dbConfig['debug'];
         $this->_dao->setDaoType($this->_daoType);
         $this->_dao->debug = $dbConfig['debug'];
     }
     //表单令牌验证
     defined('_TOKEN_ON_') && (self::$tokenOn = _TOKEN_ON_);
     defined('_TOKEN_NAME_') && (self::$tokenName = _TOKEN_NAME_);
     isset($dbConfig['dbFieldtypeCheck']) && (self::$dbFieldtypeCheck = $dbConfig['dbFieldtypeCheck']);
     // 设置表前缀
     $modelName = get_class($this);
     $refc = new ReflectionClass($modelName);
     $tpprop = $refc->getProperty('_tablePrefix');
     $decl = $tpprop->getDeclaringClass();
     if ($tpprop->class != $modelName) {
         $this->_tablePrefix = $this->_tablePrefix ? $this->_tablePrefix : @$dbConfig['tablePrefix'];
         $this->_tableSuffix = $this->_tableSuffix ? $this->_tableSuffix : @$dbConfig['tableSuffix'];
     }
     //初始化数据库名
     if ('' == $this->_dbName) {
         if (isset($dbConfig[self::DB_CFG_MASTER][self::DB_CFG_DBNAME])) {
             $this->_dbName = $dbConfig[self::DB_CFG_MASTER][self::DB_CFG_DBNAME];
         } else {
             isset($dbConfig[self::DB_CFG_DBNAME]) && ($this->_dbName = $dbConfig[self::DB_CFG_DBNAME]);
         }
     }
     $this->_dbConfig = $dbConfig;
     unset($dbConfig);
     // lazyed check table
     if (!empty($this->_tableName) && $this->_autoCheckFields) {
         // $this->_checkTableInfo();
     }
 }