浏览代码

Update action_list.rst

Fixes https://github.com/sonata-project/SonataDoctrineORMAdminBundle/issues/422.
webDEVILopers 10 年之前
父节点
当前提交
08b4dbc506
共有 1 个文件被更改,包括 23 次插入0 次删除
  1. 23 0
      Resources/doc/reference/action_list.rst

+ 23 - 0
Resources/doc/reference/action_list.rst

@@ -428,6 +428,29 @@ If you have the **SonataDoctrineORMAdminBundle** installed you can use the ``doc
             return true;
         }
     }
+    
+You can also get the filter type which can be helpful to change the operator type of your condition(s):
+
+.. code-block:: php
+
+    use Sonata\CoreBundle\Form\Type\EqualType;
+
+    class UserAdmin extends SonataUserAdmin
+    {
+        public function getFullTextFilter($queryBuilder, $alias, $field, $value)
+        {
+            if (!$value['value']) {
+                return;
+            }
+            
+            $operator = $value['type'] == EqualType::TYPE_IS_EQUAL ? '=' : '!=';
+            
+            $queryBuilder->andWhere($alias.'.username ' . $operator . ' :username')
+                         ->setParameter('username', $value['value']);
+
+            return true;
+        }
+    }
 
 To do: