From 9f383a83bfa87a4f431a887cb83be374d37b7b63 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 23 Jan 2016 15:05:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=9D=99=E6=80=81=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E6=A8=A1=E5=9E=8B=E6=96=B9=E6=B3=95=E7=9A=84ORM?= =?UTF-8?q?=E7=B1=BB=EF=BC=8C=E4=BE=8B=E5=A6=82=EF=BC=9A=20class=20User=20?= =?UTF-8?q?extends=20\think\ORM;=20User::find(1);?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/ORM.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 library/think/ORM.php diff --git a/library/think/ORM.php b/library/think/ORM.php new file mode 100644 index 00000000..eb104905 --- /dev/null +++ b/library/think/ORM.php @@ -0,0 +1,28 @@ + +// +---------------------------------------------------------------------- + +namespace think; + +class ORM +{ + protected static $instance = []; + protected static $config = []; + + public static function __callStatic($method, $params) + { + $name = basename(get_called_class()); + if (!isset(self::$instance[$name])) { + // 自动实例化模型类 + self::$instance[$name] = new \think\Model($name, static::$config); + } + return call_user_func_array([self::$instance[$name], $method], $params); + } +}