Sonata列表搜索的预定义参数

时间:2014-05-17 11:02:16

标签: php symfony sonata-admin symfony-sonata

我需要设置几个预定义的选项来显示实体列表。

奏鸣曲代码:

class SubscriptionAdmin extends Admin {
    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
    {
        $datagridMapper
            ->add('created_at')
            ->add('status', 'doctrine_orm_choice', [], 'choice', ['choices' = ['active'=>'ecmo.enum.user.active', 'inactive'=>'ecmo.enum.user.active']
        ;
}

我如何设置,默认情况下,奏鸣曲只显示活跃用户,按created_at排序?

1 个答案:

答案 0 :(得分:4)

您可以这样做,设置$ datagridValues变量的默认值,如下所示

class SubscriptionAdmin extends Admin
{   

   /**
    * Default Datagrid values
    *
    * @var array
    */
   protected $datagridValues = array (
           'status' => array ('type' => 1, 'value' => 1), // field status with value 1
           '_page' => 1, // Display the first page (default = 1)
           '_sort_order' => 'ASC', // Descendant ordering (default = 'ASC')
           '_sort_by' => 'name' // name of the ordered field (default = the model id field, if any)
      // the '_sort_by' key can be of the form 'mySubModel.mySubSubModel.myField'.
   );
}

其中'status'应该被您想要的字段替换,您应该指定所需的值,'type'值对应于以下内容:

1: =
2: >=
3: >
4: <=
5: <

这是过滤整数字段。在我的例子中,我使用了它而没有指定类型,值1被设置为默认值。

相关问题