Răsfoiți Sursa

fixed query string as bugs

朱金辉 5 luni în urmă
părinte
comite
20d63b8bbf
3 a modificat fișierele cu 15 adăugiri și 2 ștergeri
  1. 0 1
      src/Driver/Base.php
  2. 14 1
      src/Driver/Entity/Base.php
  3. 1 0
      src/Driver/Entity/Entity.php

+ 0 - 1
src/Driver/Base.php

@@ -821,7 +821,6 @@ class Base
         }else{
             $this->fields = $fields;
         }
-
         return $this;
     }
     /**

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

@@ -496,6 +496,19 @@ class Base {
     public function entity() {
         return _loadClass('\Qii\Driver\Entity\Entity');
     }
+    /**
+     * 设置查询字段
+     *
+     * @param array|string $fields 字段名称
+     * @param $args
+     * @return void
+     * @throws \Exception
+     */
+    final public function field($fields, $args = null) {
+        $this->setQueryFieldsHooker(function() use($fields){
+            return $fields;
+        }, $args);
+    }
 
     /**
      * 返回所有 Fields
@@ -1204,7 +1217,7 @@ class Base {
     public function getFields() {
         $fields = $this->getFieldsHooker();
         if(!is_array($fields)) {
-            $fields = explode(',', str_replace(" ", "", $fields));
+            $fields = explode(',', preg_replace("/\s{2,}/", " ", preg_replace("/\s(~as)/", "", $fields)));
         }
         return $fields;
     }

+ 1 - 0
src/Driver/Entity/Entity.php

@@ -142,6 +142,7 @@ class Entity {
  * @method $class setLimitHooker(\$hooker, \$args = null)
  * @method $class or(\$or, \$args = null)
  * @method $class setOrHooker(\$hooker, \$args = null)
+ * @method $class field(\$fields, \$args = null)
  * @method $class setQueryFieldsHooker(\$hooker, \$args = null)
  * @method $class get()
  * @method mixed|Response info()