Files
framework/library/think/ORM.php
thinkphp 9f383a83bf 增加静态调用模型方法的ORM类,例如:
class User extends \think\ORM;
User::find(1);
2016-01-23 15:05:01 +08:00

29 lines
1.0 KiB
PHP

<?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);
}
}