From 86387bc20126504084cf5c8508a61fff6cf3844b Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 6 Feb 2016 19:20:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3M=E5=87=BD=E6=95=B0=E5=92=8CM?= =?UTF-8?q?odel=E7=B1=BB=20=E6=94=AF=E6=8C=81=E4=BC=A0=E5=85=A5=E7=A9=BA?= =?UTF-8?q?=E7=99=BD=E7=9A=84=E8=A1=A8=E5=89=8D=E7=BC=80=20=E4=BE=8B?= =?UTF-8?q?=E5=A6=82=20M('User','')=20=E6=88=96=E8=80=85=20Loader::table('?= =?UTF-8?q?User',['prefix'=3D>'']);?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- helper.php | 4 ++-- library/think/Model.php | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/helper.php b/helper.php index d3199031..b45cb486 100644 --- a/helper.php +++ b/helper.php @@ -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]); } diff --git a/library/think/Model.php b/library/think/Model.php index 225257d8..77ef71fa 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -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'); }