2017-05-05 52 views
1

这是我ConfigureListFild如何索纳塔管理包(的createQuery方法)过滤器添加到configureListField

enter image description here

我想表明在ConfigureListFields与条件例子(我的帐户数据,其中类型=“客户” )

protected function configureListFields(ListMapper $listMapper) 
{ 
    // ... configure $listMapper 
    $listMapper 
     ->addIdentifier('raison_sociale') 
     ->add('type') 
     ->add('category.name') 
     ->add('portable') 
     ->add('ville_fac') 
     ->add('professionnel') 
     ->add('_action', 'actions', array(
     'actions' => array(
      'show' => array(), 
      'edit' => array(), 
      'delete' => array(), 
     ) 
    )) 
    ; 
} 

你能帮我显示账户类型=“客户”吗?

回答

2

你需要重写你的管理类中的createQuery方法,就像那样;

public function createQuery($context = 'list') 
{ 
     $query = parent::createQuery($context); 
     $rootAlias = $query->getRootAliases()[0]; 

     $query->andWhere(
      $query->expr()->eq($rootAlias.'.type', ':type') 
     ); 

     $query->setParameter(':type', 'Client'); 

     return $query; 
} 
+0

我该如何使用这个功能? –

+1

谢谢你的工作很好 –