Browse Source

优化返回结果

朱金辉 1 week ago
parent
commit
f247028a69
2 changed files with 13 additions and 4 deletions
  1. 11 1
      src/Driver/Entity/Base.php
  2. 2 3
      src/Library/Cookie.php

+ 11 - 1
src/Driver/Entity/Base.php

@@ -851,6 +851,16 @@ class Base {
     }
 
     /**
+     * 获取错误信息
+     * @return array
+     */
+    public function getErrorInfo() {
+        if(!$this->isError()) {
+            return ['code' => 0, 'msg' => ''];
+        }
+        return ['code' => $this->getCode(), 'msg' => $this->getMessage()];
+    }
+    /**
      * get 返回的msg
      *
      * @return string
@@ -1021,7 +1031,7 @@ class Base {
      *
      * @return false|Response
      */
-    public function remove() {
+    final public function remove() {
         if(!$this->properties() && empty($this->getWhereHooker())) {
             return Response::Fail(static::class .'::'. __FUNCTION__,
             [

+ 2 - 3
src/Library/Cookie.php

@@ -44,8 +44,7 @@ class Cookie
 		$crypt = new \Qii\Library\Crypt();
 		$crypt->setSecurityKey($this->securityKey);
 		$val = trim($crypt->encrypt(urlencode($val)));
-		setcookie($this->prefix . $name, $val, time() + $expire, '/');
-        return $val;
+		return setcookie($this->prefix . $name, $val, time() + $expire, '/');
 	}
 
 	/**
@@ -53,7 +52,7 @@ class Cookie
 	 */
 	public function get($name)
 	{
-		$val = isset($_COOKIE[$this->prefix . $name]) ? $_COOKIE[$this->prefix . $name] : '';
+		$val = isset($_COOKIE[$this->prefix . $name]) ? $_COOKIE[$this->prefix . $name] : (isset($_COOKIE[$name]) ? $_COOKIE[$name] : '');
 		if (!$val) return '';
 		$crypt = new \Qii\Library\Crypt();
 		$crypt->setSecurityKey($this->securityKey);