From a8e4ee762f0f1a9362f7a1034591af19165403c3 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 19 Jan 2016 12:18:52 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E6=94=B9=E8=BF=9BUrl=E7=B1=BB=E5=AF=B9?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E5=88=B0=E7=B1=BB=E7=9A=84=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Url.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/library/think/Url.php b/library/think/Url.php index 2f47a7e0..22addb5b 100644 --- a/library/think/Url.php +++ b/library/think/Url.php @@ -24,7 +24,7 @@ class Url * @param boolean|string $domain 是否显示域名 或者直接传入域名 * @return string */ - public static function build($url = '', $vars = '', $suffix = true, $domain = true) + public static function build($url = '', $vars = '', $suffix = true, $domain = false) { // 解析参数 if (is_string($vars)) { @@ -226,7 +226,9 @@ class Url $key = array_shift($route); } $route = $route[0]; - if (strpos($route, '?')) { + if (is_array($route)) { + $route = implode('\\', $route); + } elseif (strpos($route, '?')) { $route = strstr($route, '?', true); } $var = self::parseVar($rule . '/' . $key); @@ -234,7 +236,9 @@ class Url } } else { $route = $val['route']; - if (strpos($route, '?')) { + if (is_array($route)) { + $route = implode('\\', $route); + } elseif (strpos($route, '?')) { $route = strstr($route, '?', true); } $var = self::parseVar($rule); From ec667f83263a48339f4472f1539be5b366d4e513 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 19 Jan 2016 14:53:30 +0800 Subject: [PATCH 2/7] =?UTF-8?q?Url=E7=94=9F=E6=88=90=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E9=94=9A=E7=82=B9=EF=BC=8C=E6=94=B9=E8=BF=9B=E5=9F=9F=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Url.php | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/library/think/Url.php b/library/think/Url.php index 22addb5b..2fc5069a 100644 --- a/library/think/Url.php +++ b/library/think/Url.php @@ -26,15 +26,34 @@ class Url */ public static function build($url = '', $vars = '', $suffix = true, $domain = false) { + // 解析URL + $info = parse_url($url); + $url = !empty($info['path']) ? $info['path'] : ''; + if (isset($info['fragment'])) { + // 解析锚点 + $anchor = $info['fragment']; + if (false !== strpos($anchor, '?')) { + // 解析参数 + list($anchor, $info['query']) = explode('?', $anchor, 2); + } + if (false !== strpos($anchor, '@')) { + // 解析域名 + list($anchor, $domain) = explode('@', $anchor, 2); + } + } elseif (false !== strpos($url, '@')) { + // 解析域名 + list($url, $domain) = explode('@', $info['path'], 2); + } + // 解析参数 if (is_string($vars)) { // aaa=1&bbb=2 转换成数组 parse_str($vars, $vars); } - if (strpos($url, '?')) { - list($url, $params) = explode('?', $url); - parse_str($params, $params); + if (isset($info['query'])) { + // 解析地址里面参数 合并到vars + parse_str($info['query'], $params); $vars = array_merge($params, $vars); } @@ -63,22 +82,24 @@ class Url // URL后缀 $suffix = self::parseSuffix($suffix); + // 锚点 + $anchor = !empty($anchor) ? '#' . $anchor : ''; // 参数组装 if (!empty($vars)) { // 添加参数 if (Config::get('url_common_param')) { $vars = urldecode(http_build_query($vars)); - $url .= $suffix . '?' . $vars; + $url .= $suffix . $anchor . '?' . $vars; } else { foreach ($vars as $var => $val) { if ('' !== trim($val)) { $url .= $depr . $var . $depr . urlencode($val); } } - $url .= $suffix; + $url .= $suffix . $anchor; } } else { - $url .= $suffix; + $url .= $suffix . $anchor; } // 检测域名 @@ -136,6 +157,8 @@ class Url } } } + } else { + $domain = $domain . (strpos($domain, '.') ? '' : strstr($_SERVER['HTTP_HOST'], '.')); } $domain = (self::isSsl() ? 'https://' : 'http://') . $domain; } else { From e17ec8f9acbf940415a6ff07938d43caafdfa56c Mon Sep 17 00:00:00 2001 From: oldrind <1401019000@qq.com> Date: Tue, 19 Jan 2016 15:50:19 +0800 Subject: [PATCH 3/7] =?UTF-8?q?template=E5=8D=95=E5=85=83=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Template.php | 50 +++++++++++----------------- library/think/template/TagLib.php | 5 ++- library/think/template/taglib/Cx.php | 10 +++--- 3 files changed, 29 insertions(+), 36 deletions(-) diff --git a/library/think/Template.php b/library/think/Template.php index 8a6da9fe..ffc263b9 100644 --- a/library/think/Template.php +++ b/library/think/Template.php @@ -593,40 +593,26 @@ class Template $flag = substr($str, 0, 1); switch ($flag) { case '$': // 解析模板变量 格式 {$varName} - $this->parseVar($str); - switch ($this->config['tpl_var_identify']) { - case 'array': - $begin = 0; - break; - case 'obj': - $begin = 1; - break; - default: - // 如果是自动识别.语法,则要查找:之后的?号 - $begin = strpos($str, ':'); - } // 是否带有?号 - if (false !== $pos = strpos($str, '?', $begin)) { + if (false !== $pos = strpos($str, '?')) { $array = preg_split('/([!=]={1,2}|(?<]={0,1})/', substr($str, 0, $pos), 2, PREG_SPLIT_DELIM_CAPTURE); - $name = trim($array[0]); + $name = $array[0]; + $this->parseVar($name); $this->parseVarFunction($name); $str = trim(substr($str, $pos + 1)); + $this->parseVar($str); $first = substr($str, 0, 1); if (isset($array[1])) { - // 设置了判断条件 - // XXX: 加入这句原本是为解决变量末声明的问题,但$name中是多个条件时会解析错误,故注释掉 - /*if (strpos($name, '[')) { - $name = 'isset(' . $name . ') && ' . $name; - }*/ - $name .= $array[1] . trim($array[2]); + $this->parseVar($array[2]); + $name .= $array[1] . $array[2]; if ('=' == $first) { // {$varname?='xxx'} $varname为真时才输出xxx - $str = ''; + $str = ''; } else { - $str = ''; + $str = ''; } - } elseif ($begin || ')' == substr($name, -1, 1)) { + } elseif (')' == substr($name, -1, 1)) { // $name为对象或是自动识别,或者含有函数 switch ($first) { case '?': @@ -651,18 +637,19 @@ class Template break; case ':': // {$varname?:'xxx'} $varname为真时输出$varname,否则输出xxx - $str = ''; + $str = ''; break; default: if (strpos($str, ':')) { // {$varname ? 'a' : 'b'} $varname为真时输出a,否则输出b - $str = ''; + $str = ''; } else { $str = ''; } } } } else { + $this->parseVar($str); $this->parseVarFunction($str); $str = ''; } @@ -674,11 +661,14 @@ class Template break; case '~': // 执行某个函数 $str = substr($str, 1); + $this->parseVar($str); $str = ''; break; case '-': case '+': // 输出计算 - $str = ''; + $str = substr($str, 1); + $this->parseVar($str); + $str = ''; break; case '/': // 注释标签 $flag2 = substr($str, 1, 1); @@ -777,9 +767,9 @@ class Template switch ($fun) { case 'default': // 特殊模板函数 if (false === strpos($name, '(')) { - $name = '((isset(' . $name . ') && (' . $name . ' !== \'\')?(' . $name . '):' . $args[1] . ')'; + $name = '(isset(' . $name . ') && (' . $name . ' !== \'\')?' . $name . ':' . $args[1] . ')'; } else { - $name = '((' . $name . ' !== \'\')?(' . $name . '):' . $args[1] . ')'; + $name = '(' . $name . ' !== \'\'?' . $name . ':' . $args[1] . ')'; } break; default: // 通用模板函数 @@ -981,9 +971,9 @@ class Template $begin = $this->config['tpl_begin']; $end = $this->config['tpl_end']; if (strlen(ltrim($begin, '\\')) == 1 && strlen(ltrim($end, '\\')) == 1) { - $regex = $begin . '((?:[\$\:\-\+][a-wA-w_][\w\.\:\[\(\*\/\-\+\%_]|\/[\*\/])(?>[^' . $end . ']*))' . $end; + $regex = $begin . '((?:[\$\:\-\+~][\$a-wA-w_][\w\.\:\[\(\*\/\-\+\%_]|\/[\*\/])(?>[^' . $end . ']*))' . $end; } else { - $regex = $begin . '((?:[\$\:\-\+][a-wA-w_][\w\.\:\[\(\*\/\-\+\%_]|\/[\*\/])(?>(?:(?!' . $end . ').)*))' . $end; + $regex = $begin . '((?:[\$\:\-\+~][\$a-wA-w_][\w\.\:\[\(\*\/\-\+\%_]|\/[\*\/])(?>(?:(?!' . $end . ').)*))' . $end; } break; } diff --git a/library/think/template/TagLib.php b/library/think/template/TagLib.php index 58d2b9b9..be02d6a0 100644 --- a/library/think/template/TagLib.php +++ b/library/think/template/TagLib.php @@ -324,7 +324,10 @@ class TagLib $_taglibs[$tag][0] = strlen(ltrim($this->tpl->config('taglib_begin'), '\\') . $tag); $_taglibs[$tag][1] = strlen(ltrim($this->tpl->config('taglib_end'), '\\')); } - $result['expression'] = trim(substr($str, $_taglibs[$tag][0], -$_taglibs[$tag][1])); + $result['expression'] = substr($str, $_taglibs[$tag][0], -$_taglibs[$tag][1]); + // 清除自闭合标签尾部/ + $result['expression'] = rtrim($result['expression'], '/'); + $result['expression'] = trim($result['expression']); } elseif (empty($this->tags[$tag]) || !empty($this->tags[$tag]['attr'])) { throw new Exception('_XML_TAG_ERROR_:' . $tag); } diff --git a/library/think/template/taglib/Cx.php b/library/think/template/taglib/Cx.php index 377cb0b6..27755697 100644 --- a/library/think/template/taglib/Cx.php +++ b/library/think/template/taglib/Cx.php @@ -253,7 +253,7 @@ class Cx extends Taglib { $name = !empty($tag['expression']) ? $tag['expression'] : $tag['name']; $name = $this->autoBuildVar($name); - $parseStr = '' . $content . ''; + $parseStr = '' . $content . ''; return $parseStr; } @@ -270,20 +270,20 @@ class Cx extends Taglib $flag = substr($value, 0, 1); if ('$' == $flag || ':' == $flag) { $value = $this->autoBuildVar($value); - $value = 'case ' . $value . ': '; + $value = 'case ' . $value . ':'; } elseif (strpos($value, '|')) { $values = explode('|', $value); $value = ''; foreach ($values as $val) { - $value .= 'case "' . addslashes($val) . '": '; + $value .= 'case "' . addslashes($val) . '":'; } } else { - $value = 'case "' . $value . '": '; + $value = 'case "' . $value . '":'; } $parseStr = '' . $content; $isBreak = isset($tag['break']) ? $tag['break'] : ''; if ('' == $isBreak || $isBreak) { - $parseStr .= ''; + $parseStr .= ''; } return $parseStr; } From 5dc8d8286cb05d30f0fa11341894487334cc4e04 Mon Sep 17 00:00:00 2001 From: "xiaobo.sun" Date: Tue, 19 Jan 2016 16:07:01 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=9C=A8windows=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E4=B8=8B=EF=BC=8C=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E9=BB=98=E8=AE=A4=E8=B7=B3=E8=BD=AC=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E5=AF=B9=E5=BA=94=E7=9A=84=E6=A8=A1=E6=9D=BF=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E9=85=8D=E7=BD=AE=E5=80=BC=E7=9A=84=E6=96=9C=E6=9D=A0?= =?UTF-8?q?=E5=88=86=E5=89=B2=E7=AC=A6=E4=BC=9A=E5=AF=BC=E8=87=B4=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=E6=97=A0=E6=B3=95=E6=89=BE=E5=88=B0=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=9A=84=E9=94=99=E8=AF=AF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- convention.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/convention.php b/convention.php index 0e7d3904..33201d2e 100644 --- a/convention.php +++ b/convention.php @@ -95,7 +95,7 @@ return [ // +---------------------------------------------------------------------- // 默认跳转页面对应的模板文件 - 'dispatch_jump_tmpl' => THINK_PATH . 'tpl/dispatch_jump.tpl', + 'dispatch_jump_tmpl' => THINK_PATH . 'tpl' . DS . 'dispatch_jump.tpl', // 默认的模板引擎 'template_engine' => 'Think', @@ -104,7 +104,7 @@ return [ // +---------------------------------------------------------------------- // 异常页面的模板文件 - 'exception_tmpl' => THINK_PATH . 'tpl/think_exception.tpl', + 'exception_tmpl' => THINK_PATH . 'tpl' . DS . 'think_exception.tpl', // 错误显示信息,非调试模式有效 'error_message' => '页面错误!请稍后再试~', // 错误定向页面 From ae9a5a7bcaeab42c1435c46f880e25be81b61e3c Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 19 Jan 2016 18:54:16 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E4=BF=AE=E6=AD=A3Model=E7=B1=BB=E7=9A=84?= =?UTF-8?q?=5Fwrite=5Fdata=E6=96=B9=E6=B3=95=E6=95=B0=E6=8D=AE=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=E8=8E=B7=E5=8F=96=E4=B8=8D=E5=88=B0fields=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 22 +++++++++------ library/think/db/Driver.php | 56 ++++++++++++++++++++++++------------- 2 files changed, 49 insertions(+), 29 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 7982b3c2..9e0a9302 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -190,14 +190,15 @@ class Model } } } + $fields = $this->getDbFields(); // 检查非数据字段 - if (!empty($this->fields)) { + if (!empty($fields)) { foreach ($data as $key => $val) { - if (!in_array($key, $this->fields, true)) { + if (!in_array($key, $fields, true)) { unset($data[$key]); } elseif (is_scalar($val) && empty($this->options['bind'][':' . $key])) { // 字段类型检查 - $this->_parseType($data, $key); + $this->_parseType($data, $key, $this->options['bind']); } } } @@ -777,7 +778,7 @@ class Model $key = trim($key); if (in_array($key, $fields, true)) { if (is_scalar($val) && empty($options['bind'][':' . $key])) { - $this->_parseType($options['where'], $key); + $this->_parseType($options['where'], $key, $options['bind']); } } } @@ -799,18 +800,21 @@ class Model * @param string $key 字段名 * @return void */ - protected function _parseType(&$data, $key) + protected function _parseType(&$data, $key, &$bind) { - if (!isset($this->options['bind'][':' . $key]) && isset($this->fields['_type'][$key])) { + if (!isset($bind[':' . $key]) && isset($this->fields['_type'][$key])) { $fieldType = strtolower($this->fields['_type'][$key]); if (false !== strpos($fieldType, 'enum')) { // 支持ENUM类型优先检测 } elseif (false === strpos($fieldType, 'bigint') && false !== strpos($fieldType, 'int')) { - $data[$key] = intval($data[$key]); + $bind[':' . $key] = [$data[$key], \PDO::PARAM_INT]; + $data[$key] = ':' . $key; } elseif (false !== strpos($fieldType, 'float') || false !== strpos($fieldType, 'double')) { - $data[$key] = floatval($data[$key]); + $bind[':' . $key] = [$data[$key], \PDO::PARAM_INT]; + $data[$key] = ':' . $key; } elseif (false !== strpos($fieldType, 'bool')) { - $data[$key] = (bool) $data[$key]; + $bind[':' . $key] = [$data[$key], \PDO::PARAM_BOOL]; + $data[$key] = ':' . $key; } elseif (false !== strpos($fieldType, 'json') && is_array($data[$key])) { $data[$key] = json_encode($data[$key]); } diff --git a/library/think/db/Driver.php b/library/think/db/Driver.php index 0e0e8937..64573625 100644 --- a/library/think/db/Driver.php +++ b/library/think/db/Driver.php @@ -41,23 +41,39 @@ abstract class Driver protected $_linkID = null; // 数据库连接参数配置 protected $config = [ - 'type' => '', // 数据库类型 - 'hostname' => '127.0.0.1', // 服务器地址 - 'database' => '', // 数据库名 - 'username' => '', // 用户名 - 'password' => '', // 密码 - 'hostport' => '', // 端口 - 'dsn' => '', // - 'params' => [], // 数据库连接参数 - 'charset' => 'utf8', // 数据库编码默认采用utf8 - 'prefix' => '', // 数据库表前缀 - 'debug' => false, // 数据库调试模式 - 'deploy' => 0, // 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器) - 'rw_separate' => false, // 数据库读写是否分离 主从式有效 - 'master_num' => 1, // 读写分离后 主服务器数量 - 'slave_no' => '', // 指定从服务器序号 - 'db_like_fields' => '', // like字段自动替换为%%包裹 - 'debug' => false, // 是否调试 + // 数据库类型 + 'type' => '', + // 服务器地址 + 'hostname' => '127.0.0.1', + // 数据库名 + 'database' => '', + // 用户名 + 'username' => '', + // 密码 + 'password' => '', + // 端口 + 'hostport' => '', + 'dsn' => '', + // 数据库连接参数 + 'params' => [], + // 数据库编码默认采用utf8 + 'charset' => 'utf8', + // 数据库表前缀 + 'prefix' => '', + // 数据库调试模式 + 'debug' => false, + // 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器) + 'deploy' => 0, + // 数据库读写是否分离 主从式有效 + 'rw_separate' => false, + // 读写分离后 主服务器数量 + 'master_num' => 1, + // 指定从服务器序号 + 'slave_no' => '', + // like字段自动替换为%%包裹 + 'db_like_fields' => '', + // 是否开启数据库调试 + 'debug' => false, ]; // 数据库表达式 protected $exp = ['eq' => '=', 'neq' => '<>', 'gt' => '>', 'egt' => '>=', 'lt' => '<', 'elt' => '<=', 'notlike' => 'NOT LIKE', 'like' => 'LIKE', 'in' => 'IN', 'notin' => 'NOT IN', 'not in' => 'NOT IN', 'between' => 'BETWEEN', 'not between' => 'NOT BETWEEN', 'notbetween' => 'NOT BETWEEN']; @@ -409,7 +425,7 @@ abstract class Driver } elseif (is_scalar($val)) { // 过滤非标量数据 if (0 === strpos($val, ':') && in_array($val, array_keys($this->bind))) { - $set[] = $this->parseKey($key) . '=' . $this->quote($val); + $set[] = $this->parseKey($key) . '=' . $val; } else { $name = count($this->bind); $set[] = $this->parseKey($key) . '=:' . $name; @@ -890,7 +906,7 @@ abstract class Driver // 过滤非标量数据 $fields[] = $this->parseKey($key); if (0 === strpos($val, ':') && in_array($val, array_keys($this->bind))) { - $values[] = $this->parseValue($val); + $values[] = $val; } else { $name = count($this->bind); $values[] = ':' . $name; @@ -932,7 +948,7 @@ abstract class Driver $value[] = 'NULL'; } elseif (is_scalar($val)) { if (0 === strpos($val, ':') && in_array($val, array_keys($this->bind))) { - $value[] = $this->parseValue($val); + $value[] = $val; } else { $name = count($this->bind); $value[] = ':' . $name; From 6690126429f6631af8885d03a8fa831184ab2ed5 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 19 Jan 2016 19:05:13 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=20=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E7=BB=91=E5=AE=9A=E7=9A=84=E6=97=B6=E5=80=99?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E6=89=A7=E8=A1=8Csql=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Driver.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/library/think/db/Driver.php b/library/think/db/Driver.php index 64573625..ba68ad96 100644 --- a/library/think/db/Driver.php +++ b/library/think/db/Driver.php @@ -169,7 +169,9 @@ abstract class Driver $this->queryStr = $str; if (!empty($this->bind)) { $that = $this; - $this->queryStr = strtr($this->queryStr, array_map(function ($val) use ($that) {return $that->quote($val);}, $this->bind)); + $this->queryStr = strtr($this->queryStr, array_map(function ($val) use ($that) { + return $that->quote(is_array($val) ? $val[0] : $val); + }, $this->bind)); } if ($fetchSql) { return $this->queryStr; @@ -228,7 +230,9 @@ abstract class Driver $this->queryStr = $str; if (!empty($this->bind)) { $that = $this; - $this->queryStr = strtr($this->queryStr, array_map(function ($val) use ($that) {return $that->quote($val);}, $this->bind)); + $this->queryStr = strtr($this->queryStr, array_map(function ($val) use ($that) { + return $that->quote(is_array($val) ? $val[0] : $val); + }, $this->bind)); } if ($fetchSql) { return $this->queryStr; From 7a1dc48dfa0edd36f4cd4dea554f16215a38be47 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 19 Jan 2016 20:01:33 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E5=A2=9E=E5=8A=A0db=5Ffields=5Fstrict?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=8F=82=E6=95=B0=EF=BC=8C=E7=94=A8=E4=BA=8E?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=BD=93=E5=AD=97=E6=AE=B5=E4=B8=8D=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E7=9A=84=E6=95=B0=E6=8D=AE=E5=86=99=E5=85=A5=E7=9A=84?= =?UTF-8?q?=E6=97=B6=E5=80=99=E6=98=AF=E5=90=A6=E6=8A=9B=E5=87=BA=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=20=EF=BC=8C=E9=BB=98=E8=AE=A4=E4=B8=BAtrue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- convention.php | 1 + library/think/Model.php | 3 +++ 2 files changed, 4 insertions(+) diff --git a/convention.php b/convention.php index 33201d2e..fa1409cb 100644 --- a/convention.php +++ b/convention.php @@ -152,6 +152,7 @@ return [ // 是否启用多状态数据库配置 如果启用的话 需要跟随app_status配置不同的数据库信息 'use_db_switch' => false, + 'db_fields_strict' => true, 'database' => [ // 数据库类型 'type' => 'mysql', diff --git a/library/think/Model.php b/library/think/Model.php index 9e0a9302..c2cce2c2 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -195,6 +195,9 @@ class Model if (!empty($fields)) { foreach ($data as $key => $val) { if (!in_array($key, $fields, true)) { + if (Config::get('db_fields_strict')) { + throw new Exception(' fields not exists :[' . $key . '=>' . $val . ']'); + } unset($data[$key]); } elseif (is_scalar($val) && empty($this->options['bind'][':' . $key])) { // 字段类型检查