Переглянути джерело

Merge pull request #1719 from nicolasricci/master

update sonata admin list custom query list documentation
Thomas 11 роки тому
батько
коміт
9252765dad
1 змінених файлів з 14 додано та 2 видалено
  1. 14 2
      Resources/doc/reference/action_list.rst

+ 14 - 2
Resources/doc/reference/action_list.rst

@@ -28,9 +28,21 @@ To do:
 Customising the query used to generate the list
 -----------------------------------------------
 
-To do:
+You can customize the list query thanks to the ``createQuery`` method.
+
+.. code-block:: php
+
+    <?php
 
-- how to customize/optimize the list query
+    public function createQuery($context = 'list')
+    {
+        $query = parent::createQuery($context);
+        $query->andWhere(
+            $query->expr()->eq($query->getRootAlias() . '.my_field', ':my_param')
+        );
+        $query->setParameter('my_field', 'my_value');
+        return $query;
+    }
 
 
 Customising the sort order