mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-03 05:52:48 +08:00
增加静态调用模型方法的ORM类,例如:
class User extends \think\ORM; User::find(1);
This commit is contained in:
28
library/think/ORM.php
Normal file
28
library/think/ORM.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user