From 5d2a1bb61c5059da24027ab4ff44fc43d5db7cab Mon Sep 17 00:00:00 2001 From: tb <35296097@qq.com> Date: Thu, 30 Mar 2017 14:26:57 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 改进注释 --- library/think/Db.php | 4 +++- library/think/db/Connection.php | 6 +----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/library/think/Db.php b/library/think/Db.php index 00f719e0..3e613f7a 100644 --- a/library/think/Db.php +++ b/library/think/Db.php @@ -36,7 +36,7 @@ use think\db\Query; * @method integer update(array $data) static 更新记录 * @method integer delete(mixed $data = null) static 删除记录 * @method boolean chunk(integer $count, callable $callback, string $column = null) static 分块获取数据 - * @method mixed query(string $sql, array $bind = [], boolean $fetch = false, boolean $master = false, mixed $class = null) static SQL查询 + * @method mixed query(string $sql, array $bind = [], boolean $master = false, bool $pdo = false) static SQL查询 * @method integer execute(string $sql, array $bind = [], boolean $fetch = false, boolean $getLastInsID = false, string $sequence = null) static SQL执行 * @method Paginator paginate(integer $listRows = 15, mixed $simple = null, array $config = []) static 分页查询 * @method mixed transaction(callable $callback) static 执行数据库事务 @@ -44,6 +44,8 @@ use think\db\Query; * @method void commit() static 用于非自动提交状态下面的查询提交 * @method void rollback() static 事务回滚 * @method boolean batchQuery(array $sqlArray) static 批处理执行SQL语句 + * @method string quote(string $str) static SQL指令安全过滤 + * @method string getLastInsID($sequence = null) static 获取最近插入的ID */ class Db { diff --git a/library/think/db/Connection.php b/library/think/db/Connection.php index bc67b1d8..5e790c34 100644 --- a/library/think/db/Connection.php +++ b/library/think/db/Connection.php @@ -340,13 +340,9 @@ abstract class Connection /** * 执行查询 返回数据集 * @access public - * @param string $sql sql指令 - * @param array $bind 参数绑定 - * @param bool $master 是否在主服务器读操作 - * @param bool $class 是否返回PDO对象 * @param string $sql sql指令 * @param array $bind 参数绑定 - * @param boolean $master 是否在主服务器读操作 + * @param bool $master 是否在主服务器读操作 * @param bool $pdo 是否返回PDO对象 * @return mixed * @throws BindParamException From a489f99ef44d458c3beb3f29f4205384822505dc Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 31 Mar 2017 16:04:38 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E8=8C=83=E5=9B=B4?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=9D=99=E6=80=81=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 976823aa..bae4902f 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -1812,16 +1812,27 @@ abstract class Model implements \JsonSerializable, \ArrayAccess } } - public static function __callStatic($method, $params) + public static function __callStatic($method, $args) { + $model = new static(); + if (isset(static::$db)) { $query = static::$db; static::$db = null; } else { - $query = (new static())->db(); + $query = $model->db(); } - return call_user_func_array([$query, $method], $params); + if (method_exists($model, 'scope' . $method)) { + // 动态调用命名范围 + $method = 'scope' . $method; + array_unshift($args, $query); + + call_user_func_array([$model, $method], $args); + return $query; + } else { + return call_user_func_array([$query, $method], $args); + } } /**