From be430c15bb96c338b4c2af95da5a86f5b4bb4351 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 29 Jan 2016 16:25:16 +0800 Subject: [PATCH] =?UTF-8?q?Model=E7=B1=BB=E6=8A=9B=E5=87=BA=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=20create=E6=96=B9=E6=B3=95=E9=BB=98=E8=AE=A4=E4=BC=A0?= =?UTF-8?q?=E5=85=A5=20\think\Input::post();?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 01b715a0..81a45494 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -265,8 +265,7 @@ class Model // 重置数据 $this->data = []; } else { - $this->error = Lang::get('_DATA_TYPE_INVALID_'); - return false; + throw new Exception('invalid data'); } } // 数据处理 @@ -309,8 +308,7 @@ class Model public function addAll($dataList, $options = [], $replace = false) { if (empty($dataList)) { - $this->error = Lang::get('_DATA_TYPE_INVALID_'); - return false; + throw new Exception('no data to write') } // 数据处理 foreach ($dataList as $key => $data) { @@ -344,16 +342,14 @@ class Model // 重置数据 $this->data = []; } else { - $this->error = Lang::get('_DATA_TYPE_INVALID_'); - return false; + throw new Exception('no data require update'); } } // 数据处理 $data = $this->_write_data($data, 'update'); if (empty($data)) { // 没有数据则不执行 - $this->error = Lang::get('_DATA_TYPE_INVALID_'); - return false; + throw new Exception('no data require update'); } // 分析表达式 $options = $this->_parseOptions(); @@ -370,16 +366,14 @@ class Model $where[$field] = $data[$field]; } else { // 如果缺少复合主键数据则不执行 - $this->error = Lang::get('_OPERATION_WRONG_'); - return false; + throw new Exception('miss complex primary data'); } unset($data[$field]); } } if (!isset($where)) { // 如果没有任何更新条件则不执行 - $this->error = Lang::get('_OPERATION_WRONG_'); - return false; + throw new Exception('no data to update without where'); } else { $options['where'] = $where; } @@ -421,7 +415,7 @@ class Model if (!empty($this->data) && isset($this->data[$pk])) { return $this->delete($this->data[$pk]); } else { - return false; + throw new Exception('no data to delete without where'); } } if (is_numeric($options) || is_string($options)) { @@ -450,14 +444,14 @@ class Model } $options['where'] = $where; } else { - return false; + throw new Exception('miss complex primary data'); } } // 分析表达式 $options = $this->_parseOptions($options); if (empty($options['where'])) { // 如果条件为空 不进行删除操作 除非设置 1=1 - return false; + throw new Exception('no data to delete without where'); } if (isset($options['where'][$pk])) { $pkValue = $options['where'][$pk]; @@ -511,7 +505,7 @@ class Model } $options['where'] = $where; } else { - return false; + throw new Exception('miss complex primary data'); } } elseif (false === $options) { // 用于子查询 不查询只返回SQL @@ -689,7 +683,7 @@ class Model $condition = $this->options['where']; if (empty($condition)) { // 没有条件不做任何更新 - return false; + throw new Exception('no data to update'); } if ($lazyTime > 0) { // 延迟写入 @@ -717,7 +711,7 @@ class Model $condition = $this->options['where']; if (empty($condition)) { // 没有条件不做任何更新 - return false; + throw new Exception('no data to update'); } if ($lazyTime > 0) { // 延迟写入 @@ -867,7 +861,7 @@ class Model } $options['where'] = $where; } else { - return false; + throw new Exception('miss complex primary data'); } } // 总是查找一条记录 @@ -941,14 +935,13 @@ class Model { // 如果没有传值默认取POST数据 if (empty($data)) { - $data = $_POST; + $data = \think\Input::post(); } elseif (is_object($data)) { $data = get_object_vars($data); } // 验证数据 if (empty($data) || !is_array($data)) { - $this->error = Lang::get('_DATA_TYPE_INVALID_'); - return false; + throw new Exception('invalid data type'); } // 状态