From 1b6622fd3689f11eb356ef4bbd9533937b207e1c Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 28 Jul 2016 16:19:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BCookie=E7=B1=BB=E7=9A=84?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=88=9D=E5=A7=8B=E5=8C=96=20Controller?= =?UTF-8?q?=E7=B1=BB=E5=A2=9E=E5=8A=A0=5Finitialize=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Controller.php | 11 +++++++---- library/think/Cookie.php | 9 ++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/library/think/Controller.php b/library/think/Controller.php index a34d90fd..941ffd18 100644 --- a/library/think/Controller.php +++ b/library/think/Controller.php @@ -50,9 +50,7 @@ class Controller $this->request = $request; // 控制器初始化 - if (method_exists($this, '_initialize')) { - $this->_initialize(); - } + $this->_initialize(); // 前置操作方法 if ($this->beforeActionList) { @@ -64,6 +62,11 @@ class Controller } } + // 初始化 + protected function _initialize() + { + } + /** * 前置操作 * @access protected @@ -183,7 +186,7 @@ class Controller } } // 是否批量验证 - if($batch || $this->batchValidate){ + if ($batch || $this->batchValidate) { $v->batch(true); } diff --git a/library/think/Cookie.php b/library/think/Cookie.php index eb31c769..648b2c60 100644 --- a/library/think/Cookie.php +++ b/library/think/Cookie.php @@ -30,6 +30,8 @@ class Cookie 'setcookie' => true, ]; + protected static $init; + /** * Cookie初始化 * @param array $config @@ -44,6 +46,7 @@ class Cookie if (!empty(self::$config['httponly'])) { ini_set('session.cookie_httponly', 1); } + self::$init = true; } /** @@ -71,6 +74,7 @@ class Cookie */ public static function set($name, $value = '', $option = null) { + !isset(self::$init) && self::init(); // 参数设置(会覆盖黙认设置) if (!is_null($option)) { if (is_numeric($option)) { @@ -103,6 +107,7 @@ class Cookie */ public static function has($name, $prefix = null) { + !isset(self::$init) && self::init(); $prefix = !is_null($prefix) ? $prefix : self::$config['prefix']; $name = $prefix . $name; return isset($_COOKIE[$name]); @@ -116,6 +121,7 @@ class Cookie */ public static function get($name, $prefix = null) { + !isset(self::$init) && self::init(); $prefix = !is_null($prefix) ? $prefix : self::$config['prefix']; $name = $prefix . $name; if (isset($_COOKIE[$name])) { @@ -139,6 +145,7 @@ class Cookie */ public static function delete($name, $prefix = null) { + !isset(self::$init) && self::init(); $config = self::$config; $prefix = !is_null($prefix) ? $prefix : $config['prefix']; $name = $prefix . $name; @@ -160,7 +167,7 @@ class Cookie if (empty($_COOKIE)) { return; } - + !isset(self::$init) && self::init(); // 要删除的cookie前缀,不指定则删除config设置的指定前缀 $config = self::$config; $prefix = !is_null($prefix) ? $prefix : $config['prefix'];