[英]How to add filter to configureListField in Sonata Admin Bundle (createQuery method)
這是我的ConfigureListFild
:
我想使用條件示例(其中type ='client')在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(),
)
))
;
}
您能幫我按類型顯示“客戶”帳戶列表嗎?
您需要在管理類中重寫諸如此類的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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.