2013-09-04 8 views
3

ZF2, Doctrine ORM 및 BjyAuthorize로 작업하고 있습니다.로그인 할 때 BjyAuthorize가 감지하지 못함

문제는 아이디의 getRoles 메소드가 비어있는 상태로 반환된다는 것입니다.

class User implements UserInterface, ProviderInterface{ 

/** 
    * @var \Doctrine\Common\Collections\Collection 
    * 
    * @ORM\ManyToMany(targetEntity="Application\Entity\Role", inversedBy="user") 
    * @ORM\JoinTable(name="user_role_linker", 
    * joinColumns={ 
    *  @ORM\JoinColumn(name="user_id", referencedColumnName="user_id") 
    * }, 
    * inverseJoinColumns={ 
    *  @ORM\JoinColumn(name="role_id", referencedColumnName="id") 
    * } 
    *) 
    */ 
    protected $roles; 

    public function __construct() { 
     $this->roles = new \Doctrine\Common\Collections\ArrayCollection(); 
    } 

public function addRole(\Application\Entity\Role $role) { 
     $this->roles[] = $role; 

     return $this; 
    } 

    /** 
    * Remove role 
    * 
    * @param \Application\Entity\Role $role 
    */ 
    public function removeRole(\Application\Entity\Role $role) { 
     $this->roles->removeElement($role); 
    } 

    /** 
    * Get role 
    * 
    * @return \Doctrine\Common\Collections\Collection 
    */ 

    public function getRoles() { 
     return $this->roles->getValues(); 
    } 
} 

반면에 컨트롤러에서 엔티티를 가져와 getRoles를 사용하면 아무런 문제없이 값을 얻을 수 있습니다.

어느 것이 문제 일 수 있습니까?

이 내 ZFC-사용자 교리-ORM-전역 :

<?php 
return array(
    'doctrine' => array(
     'driver' => array(
      // overriding zfc-user-doctrine-orm's config 
      'zfcuser_entity' => array(
       'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver', 
       'paths' => 'module\Application\src\Application\Entity', 
      ), 

      'orm_default' => array(
       'drivers' => array(
        'Application' => 'zfcuser_entity', 
       ), 
      ), 
     ), 
    ), 

    'zfcuser' => array(
     // telling ZfcUser to use our own class 
     'user_entity_class'  => '\Application\Entity\User', 
     // telling ZfcUserDoctrineORM to skip the entities it defines 
     'enable_default_entities' => false, 
    ), 

    'bjyauthorize' => array(
     // Using the authentication identity provider, which basically reads the roles from the auth service's identity 
     'identity_provider' => 'BjyAuthorize\Provider\Identity\AuthenticationIdentityProvider', 

     'role_providers'  => array(
      // using an object repository (entity repository) to load all roles into our ACL 
      'BjyAuthorize\Provider\Role\ObjectRepositoryProvider' => array(
       'object_manager' => 'doctrine.entitymanager.orm_default', 
       'role_entity_class' => 'Application\Entity\Role', 
      ), 
     ), 
    ), 
); 

답변

0

은 당신이 당신의 역할이 '역할'테이블에 정의하고, 사용자 ID <가 있습니까 -> 역할 ID user_role_linker 테이블에?