From acd3e6fa2545d3afc33603345b3657c622685dbd Mon Sep 17 00:00:00 2001 From: molong Date: Fri, 2 Sep 2016 15:02:37 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=86=85=E6=A0=B8=E6=9B=B4=E6=96=B0=202.?= =?UTF-8?q?=E8=A7=84=E5=88=99=E4=BB=8E=E8=8F=9C=E5=8D=95=E4=B8=AD=E6=89=B9?= =?UTF-8?q?=E9=87=8F=E5=AF=BC=E5=85=A5bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/Group.php | 21 ++++---------------- application/common/model/AuthRule.php | 22 ++++++++++++++++++++- core/library/think/App.php | 1 + core/library/think/Model.php | 1 + core/library/think/Request.php | 2 +- core/library/think/cache/driver/Redis.php | 5 +++++ core/library/think/db/Query.php | 3 +++ core/library/think/session/driver/Redis.php | 6 ++++++ 8 files changed, 42 insertions(+), 19 deletions(-) diff --git a/application/admin/controller/Group.php b/application/admin/controller/Group.php index e1a5bf1a..5c9d5e58 100644 --- a/application/admin/controller/Group.php +++ b/application/admin/controller/Group.php @@ -127,26 +127,13 @@ class Group extends Admin { //根据菜单更新节点 public function upnode($type) { $rule = model('Menu')->getAuthNodes($type); - foreach ($rule as $value) { - $data = array( - 'module' => $type, - 'type' => 2, - 'name' => $value['url'], - 'title' => $value['title'], - 'group' => $value['group'], - 'status' => 1, - ); - $id = $this->rule->where(array('name' => $data['name']))->value('id'); - if ($id) { - $data['id'] = $id; - $this->rule->save($data, array('id' => $id)); - } else { - $this->rule->save($data); - } - } + $reuslt = $this->rule->uprule($rule, $type); return $this->success("更新成功!"); } + /** + * 授权 + */ public function auth($id) { if (!$id) { return $this->error("非法操作!"); diff --git a/application/common/model/AuthRule.php b/application/common/model/AuthRule.php index d00e5b8c..a570a8b9 100644 --- a/application/common/model/AuthRule.php +++ b/application/common/model/AuthRule.php @@ -22,7 +22,6 @@ class AuthRule extends Base{ ); public $keyList = array( - //array('name'=>'id','title'=>'标识','type'=>'hidden'), array('name'=>'module','title'=>'所属模块','type'=>'hidden'), array('name'=>'title','title'=>'节点名称','type'=>'text','help'=>''), array('name'=>'name','title'=>'节点标识','type'=>'text','help'=>''), @@ -30,4 +29,25 @@ class AuthRule extends Base{ array('name'=>'status','title'=>'状态','type'=>'select','option'=>array('1'=>'启用','0'=>'禁用'),'help'=>''), array('name'=>'condition','title'=>'条件','type'=>'text','help'=>'') ); + + public function uprule($data, $type){ + foreach ($data as $value) { + $data = array( + 'module' => $type, + 'type' => 2, + 'name' => $value['url'], + 'title' => $value['title'], + 'group' => $value['group'], + 'status' => 1, + ); + $id = $this->where(array('name' => $data['name']))->value('id'); + if ($id) { + $data['id'] = $id; + $this->save($data, array('id' => $id)); + } else { + self::create($data); + } + } + return true; + } } \ No newline at end of file diff --git a/core/library/think/App.php b/core/library/think/App.php index bfaca8d2..d10945f5 100644 --- a/core/library/think/App.php +++ b/core/library/think/App.php @@ -242,6 +242,7 @@ class App { $args = []; // 判断数组类型 数字数组时按顺序绑定参数 + reset($vars); $type = key($vars) === 0 ? 1 : 0; if ($reflect->getNumberOfParameters() > 0) { $params = $reflect->getParameters(); diff --git a/core/library/think/Model.php b/core/library/think/Model.php index e5a107f8..02cb6854 100644 --- a/core/library/think/Model.php +++ b/core/library/think/Model.php @@ -629,6 +629,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess // 检测字段 if (!empty($this->field)) { + $this->db(); foreach ($this->data as $key => $val) { if (!in_array($key, $this->field)) { unset($this->data[$key]); diff --git a/core/library/think/Request.php b/core/library/think/Request.php index ccae2842..5b588cde 100644 --- a/core/library/think/Request.php +++ b/core/library/think/Request.php @@ -93,7 +93,6 @@ class Request * @var array 资源类型 */ protected $mimeType = [ - 'html' => 'text/html,application/xhtml+xml,*/*', 'xml' => 'application/xml,text/xml,application/x-xml', 'json' => 'application/json,text/x-json,application/jsonrequest,text/json', 'js' => 'text/javascript,application/javascript,application/x-javascript', @@ -107,6 +106,7 @@ class Request 'jpg' => 'image/jpg,image/jpeg,image/pjpeg', 'gif' => 'image/gif', 'csv' => 'text/csv', + 'html' => 'text/html,application/xhtml+xml,*/*', ]; protected $content; diff --git a/core/library/think/cache/driver/Redis.php b/core/library/think/cache/driver/Redis.php index cd33523f..1f8686af 100644 --- a/core/library/think/cache/driver/Redis.php +++ b/core/library/think/cache/driver/Redis.php @@ -27,6 +27,7 @@ class Redis extends Driver 'host' => '127.0.0.1', 'port' => 6379, 'password' => '', + 'select' => 0, 'timeout' => 0, 'expire' => 0, 'persistent' => false, @@ -53,6 +54,10 @@ class Redis extends Driver if ('' != $this->options['password']) { $this->handler->auth($this->options['password']); } + + if (0 != $this->options['select']) { + $this->handler->select($this->options['select']); + } } /** diff --git a/core/library/think/db/Query.php b/core/library/think/db/Query.php index 1d51cc54..10ed25b1 100644 --- a/core/library/think/db/Query.php +++ b/core/library/think/db/Query.php @@ -1980,6 +1980,9 @@ class Query $model = $this->model; $data = new $model($data); $data->isUpdate(true, isset($options['where']['AND']) ? $options['where']['AND'] : null); + if ($this->allowField) { + $data->allowField($this->allowField); + } // 关联查询 if (!empty($options['relation'])) { $data->relationQuery($options['relation']); diff --git a/core/library/think/session/driver/Redis.php b/core/library/think/session/driver/Redis.php index 367df10c..e3dc9983 100644 --- a/core/library/think/session/driver/Redis.php +++ b/core/library/think/session/driver/Redis.php @@ -22,6 +22,7 @@ class Redis extends SessionHandler 'host' => '127.0.0.1', // redis主机 'port' => 6379, // redis端口 'password' => '', // 密码 + 'select' => 0, // 操作库 'expire' => 3600, // 有效期(秒) 'timeout' => 0, // 超时时间(秒) 'persistent' => true, // 是否长连接 @@ -56,6 +57,11 @@ class Redis extends SessionHandler if ('' != $this->config['password']) { $this->handler->auth($this->config['password']); } + + if (0 != $this->config['select']) { + $this->handler->select($this->config['select']); + } + return true; }