From 301c1b9f3ff2c5e643256c84070debafc4ce5b2c Mon Sep 17 00:00:00 2001 From: huangdijia Date: Thu, 17 Dec 2015 11:31:14 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E6=AD=A3mongo=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E4=B8=8D=E8=83=BD=E8=BF=9E=E6=8E=A5=E5=8F=8A=E6=8A=A5setField?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E4=B8=8D=E5=AD=98=E5=9C=A8=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/driver/mongo.php | 4 +++- library/think/model/mongo.php | 11 ++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/library/think/db/driver/mongo.php b/library/think/db/driver/mongo.php index 8eda7ea1..384ec1e8 100644 --- a/library/think/db/driver/mongo.php +++ b/library/think/db/driver/mongo.php @@ -65,7 +65,7 @@ class Mongo extends Driver { if (!isset($this->linkID[$linkNum])) { if (empty($config)) { - $config = $this->config['connection']; + $config = $this->config; } $host = 'mongodb://' . ($config['username'] ? "{$config['username']}" : '') . ($config['password'] ? ":{$config['password']}@" : '') . $config['hostname'] . ($config['hostport'] ? ":{$config['hostport']}" : '') . '/' . ($config['database'] ? "{$config['database']}" : ''); @@ -95,6 +95,8 @@ class Mongo extends Driver $this->initConnect($master); } + $db = $db?$db:$this->config['database']; + try { if (!empty($db)) { // 传人Db则切换数据库 diff --git a/library/think/model/mongo.php b/library/think/model/mongo.php index d62c7f3c..ab599481 100644 --- a/library/think/model/mongo.php +++ b/library/think/model/mongo.php @@ -13,12 +13,16 @@ namespace think\model; use think\Lang; use think\Loader; +T('modle/adv'); + /** * MongoModel模型类 * 实现了ODM和ActiveRecords模式 */ class Mongo extends \Think\Model { + use \traits\model\adv; + // 主键类型 const TYPE_OBJECT = 1; const TYPE_INT = 2; @@ -164,7 +168,7 @@ class Mongo extends \Think\Model return false; } if (empty($result)) { -// 查询结果为空 + // 查询结果为空 return null; } else { $this->checkMongoId($result); @@ -237,9 +241,10 @@ class Mongo extends \Think\Model } else { // 返回数据个数 if (true !== $sepa) { -// 当sepa指定为true的时候 返回所有数据 + // 当sepa指定为true的时候 返回所有数据 $options['limit'] = is_numeric($sepa) ? $sepa : 1; - } // 查找一条记录 + } + // 查找一条记录 $result = $this->db->find($options); if (!empty($result)) { if (1 == $options['limit']) { From 0bb13ec16ab0dabb94d19f872908ca414a592dc0 Mon Sep 17 00:00:00 2001 From: huangdijia Date: Thu, 17 Dec 2015 11:56:16 +0800 Subject: [PATCH 2/3] =?UTF-8?q?success/error=E6=96=B9=E6=B3=95=E6=94=AF?= =?UTF-8?q?=E6=8C=81ajax?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/traits/controller/view.php | 1 + 1 file changed, 1 insertion(+) diff --git a/library/traits/controller/view.php b/library/traits/controller/view.php index 6b10e0a9..e7df4e7c 100644 --- a/library/traits/controller/view.php +++ b/library/traits/controller/view.php @@ -92,6 +92,7 @@ trait View 'url' => $url, 'wait' => $wait, ]; + IS_AJAX && Config::set('default_return_type', Config::get('default_ajax_return')); if ('html' == Config::get('default_return_type')) { return $this->fetch(Config::get('dispatch_jump_tmpl'), $result); } else { From 098eae6aa0f224f712e6a6fd20b9a4811df40f19 Mon Sep 17 00:00:00 2001 From: huangdijia Date: Thu, 17 Dec 2015 11:59:30 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=BC=BA=E5=8C=96success/error=E6=96=B9?= =?UTF-8?q?=E6=B3=95=EF=BC=8C=E6=94=AF=E6=8C=81=E6=95=B0=E6=8D=AE=E8=BF=94?= =?UTF-8?q?=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/traits/controller/view.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/traits/controller/view.php b/library/traits/controller/view.php index e7df4e7c..664f34b2 100644 --- a/library/traits/controller/view.php +++ b/library/traits/controller/view.php @@ -108,10 +108,10 @@ trait View * @param integer $wait 跳转等待时间 * @return void */ - protected function error($message, $jumpUrl = '', $wait = 5) + protected function error($message, $data = '', $jumpUrl = '', $wait = 5) { $jumpUrl = $jumpUrl ?: 'javascript:history.back(-1);'; - return $this->result('', $message, 0, $jumpUrl, $wait); + return $this->result($data, $message, 0, $jumpUrl, $wait); } /** @@ -122,10 +122,10 @@ trait View * @param integer $wait 跳转等待时间 * @return void */ - protected function success($message, $jumpUrl = '', $wait = 3) + protected function success($message, $data = '', $jumpUrl = '', $wait = 3) { $jumpUrl = $jumpUrl ?: $_SERVER["HTTP_REFERER"]; - return $this->result('', $message, 1, $jumpUrl, $wait); + return $this->result($data, $message, 1, $jumpUrl, $wait); } }