我使用symfony 2.8和sonataAdminBundle,在BackOffice中我喜欢看到两种类型的用户"客户端"和#34;通讯员" ,这两个用户拥有相同的实体"用户"我已经通过字段"类型"区分这两个用户。 ,我已经像这样创建了AdminClasse:
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
我总是声明上一个服务结果的问题(在本期中,结果始终是"客户端"在#34;客户端"以及&#的视图中34;通讯员"
有人可以帮我吗?
答案 0 :(得分:2)
你清除缓存了吗?你的Admin.yml格式正确吗?
修改强> 两个管理类可能都有相同的路由。尝试为每个管理员定义自己的路线。在那之后清除缓存。
<强> 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;
...