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'];