1
我使用symfony 2.8和sonataAdminBundle,在BackOffice中我喜歡看到兩種類型的用戶「客戶端」和「對應」,這兩個用戶具有相同的實體「用戶」,我已經區分了這兩個用戶通過字段 「類型」,我已經創造AdminClasse這樣的:顯示用戶實體SonataAdminBundle
CorrespondantAdmin
class CorrespondantAdmin extends AbstractAdmin
{
public function createQuery($context = 'list')
{
$query = parent::createQuery($context);
$query->andWhere(
$query->expr()->eq($query->getRootAliases()[0] . '.type', ':my_param')
);
$query->setParameter('my_param', 'correspondant');
return $query;
}
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('nom')
->add('prenom')
->add('email')
->add('civilite')
->add('dateInscrit')
->add('_action', 'actions', array(
'actions' => array(
'show' => array(),
'edit' => array(),
)
))
;
}
ClientAdmin
class ClientAdmin extends AbstractAdmin
{
public function createQuery($context = 'list')
{
$query = parent::createQuery($context);
$query->andWhere(
$query->expr()->eq($query->getRootAliases()[0] . '.type', ':my_param')
);
$query->setParameter('my_param', 'client');
return $query;
}
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('nom')
->add('prenom')
->add('email')
->add('civilite')
->add('dateInscrit')
->add('_action', 'actions', array(
'actions' => array(
'show' => array(),
'edit' => array(),
)
))
;
}
Admin.yml
app.admin.correspondant:
class: Devagnos\AdminBundle\Admin\CorrespondantAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: "Utilisateurs", label: "Mes Correspondants" }
arguments:
- ~
- Devagnos\UserBundle\Entity\User
- ~
calls:
- [ setTranslationDomain, [AdminBundle]]
public: true
app.admin.client:
class: Devagnos\AdminBundle\Admin\ClientAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: "Utilisateurs", label: "Mes Clients" }
arguments:
- ~
- Devagnos\UserBundle\Entity\User
- ~
calls:
- [ setTranslationDomain, [AdminBundle]]
public: true
我必須聲明的最後一個服務的總的結果(在這個問題上的結果總是在「客戶」視圖中的「客戶端」和問題「對應」
有人可以幫助我嗎?
是我做的,但同樣的問題 –
我編輯我的答案 –
非常感謝它做工精細;) –