修正M函数实例化问题 D函数自动实例化公共模块的模型

This commit is contained in:
thinkphp
2015-12-11 08:23:54 +08:00
parent 3440c28552
commit 01cc676a7a
2 changed files with 17 additions and 12 deletions

View File

@@ -149,13 +149,17 @@ class Loader
return $_model[$name . $layer];
}
if (strpos($name, '/')) {
list($module, $name) = explode('/', $name);
list($module, $name) = explode('/', $name, 2);
} else {
$module = MODULE_NAME;
}
$class = $module . '\\' . $layer . '\\' . self::parseName(str_replace('.', '\\', $name), 1);
$class = $module . '\\' . $layer . '\\' . self::parseName(str_replace('/', '\\', $name), 1);
if (class_exists($class)) {
$model = new $class($name);
} elseif (false === strpos($name, '/')) {
// 自动加载公共模块下面的模型
$class = COMMON_MODULE . strstr($class, '\\');
$model = class_exists($class) ? new $class($name) : new Model($name);
} else {
Log::record('实例化不存在的类:' . $class, 'NOTIC');
$model = new Model($name);

View File

@@ -50,7 +50,6 @@ class Model
/**
* 架构函数
* 取得DB类的实例对象 字段检查
* @access public
* @param string $name 模型名称
* @param array $config 模型配置
@@ -70,21 +69,21 @@ class Model
list($this->dbName, $this->name) = explode('.', $this->name);
}
if (isset($config['prefix'])) {
if (!empty($config['prefix'])) {
$this->tablePrefix = $config['prefix'];
} else {
$this->tablePrefix = Config::get('database.prefix');
}
if (isset($config['connection'])) {
if (!empty($config['connection'])) {
$this->connection = $config['connection'];
}
if (isset($config['table_name'])) {
if (!empty($config['table_name'])) {
$this->tableName = $config['table_name'];
}
if (isset($config['true_table_name'])) {
if (!empty($config['true_table_name'])) {
$this->trueTableName = $config['true_table_name'];
}
if (isset($config['db_name'])) {
if (!empty($config['db_name'])) {
$this->dbName = $config['db_name'];
}
@@ -999,7 +998,7 @@ class Model
}
return $this;
}
/**
* 查询SQL组装 join
* @access public
@@ -1010,7 +1009,10 @@ class Model
*/
public function join($join, $condition = null, $type = 'INNER')
{
if (empty($join)) return $this;
if (empty($join)) {
return $this;
}
if (empty($condition)) {
if (is_array($join) && is_array($join[0])) {
// 如果为组数则循环调用join
@@ -1023,7 +1025,7 @@ class Model
$this->_join($join, $condition); // 兼容原来的join写法
}
} elseif (in_array(strtoupper($condition), array('INNER', 'LEFT', 'RIGHT', 'ALL'))) {
$this->_join($join, $condition); // 兼容原来的join写法
$this->_join($join, $condition); // 兼容原来的join写法
} else {
$prefix = $this->tablePrefix;
// 传入的表名为数组
@@ -1065,7 +1067,6 @@ class Model
return $this;
}
/**
* 查询SQL组装 union
* @access public