From e7929c419b75fddaafde21e5b2e32432f81b800d Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 29 Sep 2016 16:27:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E6=A8=A1=E5=9E=8B=E5=9C=A8?= =?UTF-8?q?=E5=BC=80=E5=90=AFclass=5Fsuffix=E5=8F=82=E6=95=B0=E6=83=85?= =?UTF-8?q?=E5=86=B5=E4=B8=8B=E7=9A=84name=E5=B1=9E=E6=80=A7=E7=9A=84?= =?UTF-8?q?=E8=AF=86=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/library/think/Model.php b/library/think/Model.php index 6ac90cc8..c276d872 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -13,6 +13,7 @@ namespace think; use InvalidArgumentException; use think\Cache; +use think\Config; use think\Db; use think\db\Query; use think\Exception; @@ -126,7 +127,12 @@ abstract class Model implements \JsonSerializable, \ArrayAccess if (empty($this->name)) { // 当前模型名 - $this->name = basename(str_replace('\\', '/', $this->class)); + $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)) {