2017-08-01 84 views
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 

我必須聲明的最後一個服務的總的結果(在這個問題上的結果總是在「客戶」視圖中的「客戶端」和問題「對應」

有人可以幫助我嗎?

回答

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; 


    ... 
+0

是我做的,但同樣的問題 –

+0

我編輯我的答案 –

+0

非常感謝它做工精細;) –