修正M函数和Model类 支持传入空白的表前缀

例如 M('User','') 或者 Loader::table('User',['prefix'=>'']);
This commit is contained in:
thinkphp
2016-02-06 19:20:16 +08:00
parent bc6b7e353f
commit 86387bc201
2 changed files with 4 additions and 2 deletions

View File

@@ -72,11 +72,11 @@ function G($start, $end = '', $dec = 6)
/**
* 实例化一个没有模型文件的Model
* @param string $name Model名称 支持指定基础模型 例如 MongoModel:User
* @param string $tablePrefix 表前缀
* @param string|null $tablePrefix 表前缀 null表示自动获取配置
* @param mixed $connection 数据库连接信息
* @return \Think\Model
*/
function M($name = '', $tablePrefix = '', $connection = '')
function M($name = '', $tablePrefix = null, $connection = '')
{
return \think\Loader::table($name, ['prefix' => $tablePrefix, 'connection' => $connection]);
}

View File

@@ -76,6 +76,8 @@ class Model
if (!empty($config['prefix'])) {
$this->tablePrefix = $config['prefix'];
} elseif ('' === $config['prefix']) {
$this->tablePrefix = '';
} elseif (is_null($this->tablePrefix)) {
$this->tablePrefix = Config::get('database.prefix');
}