2012-06-11 4 views
1

DB에서 사용자를로드하기위한 Symfony2 요리 책 자습서를 따르려고합니다.Symfony2 cookbook DB 튜토리얼 - 리포지토리 클래스가 누락되었습니다.

이 튜토리얼에서는 ACME/UserBundle이 있다고 가정하고 설치를하지는 않지만 방금 직접 만들 수 있다고 가정했습니다 (어딘가에 다운로드해야하는 플러그인 패키지와 같지 않습니까?).

UserBundle 번들을 생성하고 튜토리얼 엔티티 User (첫 번째 코드 상자 here)의 코드를 복사하여 붙여 넣었습니다.

이 라인은 나를 위해 일을 깰 것 같다

@ORM\Entity(repositoryClass="Mycompany\UserBundle\Entity\UserRepository") 

내가 오류 메시지는 다음과 같습니다

Fatal error: Class 'mycompany\UserBundle\Entity\UserRepository' not 
found in /var/www/mycompany/vendor/doctrine/lib/Doctrine/ORM/EntityManager.php 
on line 578 

그래서 내가 하나가 이후 (이상한 난 그냥 내 자신의 UserBundle을 만들 수 없습니다 가정 어떻게하는지에 대한 튜토리얼이라고 생각했는데, 플러그인을 설치하는 방법이 아닙니다.) 또는 어떻게 든 엔티티 리포지토리간에 엔티티를 어떻게 든 등록해야한다는 것을 알고 있다고 가정했습니다.

심포니에서 더 많은 사람들이 저를 계몽 해 주시면 고맙게 생각합니다. 지금까지 Symfony2에 대해 배웠던 모든 것을 진실로 사랑합니다.하지만 저는 약간 느린 학습자입니다.

답변

1

그것은 소리,이 사용자 엔티티 클래스에 별도입니다. 그것은 엔티티 폴더에 이동하지만 UserRepository.php을하고 같은 보일 것이다 :이 클래스를 사용하면 http://symfony.com/doc/current/cookbook/security/entity_provider.html

+0

사실, 자습서가 읽는 방법과 달리,이 클래스는 userBundle이 선택 사항으로 보이는 것처럼, 사용자 이름이나 이메일로 로그인하는 방법으로 사용되므로 모든 것이 그것없이 끊어서는 안됩니다 ... –

+0

그게 전부입니다 일종의 사실이지만 질문에 언급 한 행을 가진 엔티티 클래스의 저장소를 선언했기 때문에이를 가지고 있어야합니다. userprovider 인터페이스를 확장하지 않으면 내 대답처럼 미리 채울 필요가 없습니다. – Luke

0

doctrine:generate:entities 명령을 사용하여 올바른 클래스를 생성 할 수 있어야합니다.

(Documented in the book.) 내가 명령은 다음과 같이해야한다고 생각 : 사용자 저장소 클래스를 해달라고처럼

php app/console doctrine:generate:entities User 
+0

아하을하고있는 튜토리얼 아래로 사용할 수 학습과입니다

namespace Mycompany\UserBundle\Entity; use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\User\UserProviderInterface; use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; use Symfony\Component\Security\Core\Exception\UnsupportedUserException; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\NoResultException; // Implements userproviderinterface so we can use the user entity for authentication // Extends entityrepository so that it gets methods definded there class UserRepository extends EntityRepository implements UserProviderInterface { // This function is called when a user tries to login, the below lets the user use their username or email for username public function loadUserByUsername($username) { $user = $this->createQueryBuilder('u') ->select('u, r') ->leftJoin('u.roles', 'r') ->where('u.username = :username OR u.email = :username') ->setParameter('username', $username) ->getQuery(); try { $user = $user->getSingleResult(); } catch (NoResultException $exc) { throw new UsernameNotFoundException(sprintf('Unable to find an active UserBundle:User object identified by %s', $username)); } return $user; } // public function refreshUser(UserInterface $user) { $class = get_class($user); if (!$this->supportsClass($class)) throw new UnsupportedUserException(sprintf('instances of class %s are not supported', $class)); return $this->loadUserByUsername($user->getUsername()); } public function supportsClass($class) { return $this->getEntityName() === $class || is_subclass_of($class, $this->getEntityName()); } } 

을, 나는 명령 그냥 몇 가지를 자동으로 생성 생각 엔티티에 대한 함수, 나는 당신이 실제로 코드에서 엔티티 클래스를 생성하기 위해 실행해야한다는 것을 이해하지 못했습니다. –

관련 문제