Reputation: 260
I work with symfony 2.8 and sonataAdminBundle, in the BackOffice I like to see two type of users "Client" and "Correspondant" , this two users have the same Entity "User" and I have differenciate this two user by a field "type" , I have create to AdminClasse like this :
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
the problem that I have always the result of the last service declared (in this issue the result is always the "client" in the view of "Client" and of the "Correspondant"
Someone can help me please ?
Upvotes: 1
Views: 77
Reputation: 103
Did you clear the cache? Is your Admin.yml properly formatted?
Edit: You probably have same route for both admin classes. Try define own route for each admin. After that clear cache.
ClientAdmin
class ClientAdmin extends AbstractAdmin
{
const ROUTE = 'client-user';
protected $baseRoutePattern = self::ROUTE;
protected $baseRouteName = self::ROUTE;
...
CorrespondantAdmin
class CorrespondantAdmin extends AbstractAdmin
{
const ROUTE = 'correspondant-user';
protected $baseRoutePattern = self::ROUTE;
protected $baseRouteName = self::ROUTE;
...
Upvotes: 2