Co krok to problem, może Wy pomożecie, bo gotowy kod z dokumentacji po prostu nie działa.
Podłączyłem bazę do security zgodnie z: http://symfony.com/doc/2.2/cookbook/securi...y_provider.html
No wziąłem ich kod analogicznie wprowadziłem zmiany i błąd.
Formularz się pojawia, wszytko śmiga bez baz z bazą jest problem.
[u]FatalErrorException: Error: Call to undefined method Backend\CmsBundle\Entity\User::getId() in C:\wamp\www\zw\src\Backend\CmsBundle\Entity\UserRepository.php line 50[/u]
Kojarzy ktoś może dlaczego nie może załadować $user->getId() z lini 50? Przecież jest UserInterface $user wyżej. Załadowany też jest. No to jest ich kod... no nie działa.
No z nieba sobie nie wymyśle, co oni zrobili źle, może Wy spotkaliście się z tym Bug-iem?
Mój security.
security: encoders: Backend\CmsBundle\Entity\User: algorithm: sha1 encode_as_base64: false iterations: 1 role_hierarchy: ROLE_ADMIN: ROLE_USER ROLE_SUPER_ADMIN: [ ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH ] providers: administrators: entity: { class: BackendCmsBundle:User, property: username } firewalls: admin_area: pattern: ^/admin http_basic: ~ secured_area: pattern: ^/ form_login: check_path: login_check login_path: login logout: path: _logout target: _logout_place anonymous: ~ access_control: - { path: ^/admin, roles: ROLE_ADMIN }
Moj User.php => ENTITY
// src/Backend/CmsBundle/Entity/User.php namespace Backend\CmsBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\User\EquatableInterface; /** * Acme\UserBundle\Entity\User * * @ORM\Table(name="sz_users") * @ORM\Entity(repositoryClass="Backend\CmsBundle\Entity\UserRepository") */ class User implements UserInterface, \Serializable { /** * @ORM\Column(type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @ORM\Column(type="string", length=25, unique=true) */ private $username; /** * @ORM\Column(type="string", length=32) */ private $salt; /** * @ORM\Column(type="string", length=40) */ private $password; /** * @ORM\Column(type="string", length=60, unique=true) */ private $email; /** * @ORM\Column(name="is_active", type="boolean") */ private $isActive; public function __construct() { $this->isActive = true; } /** * @inheritDoc */ public function getUsername() { return $this->username; } /** * @inheritDoc */ public function getSalt() { return $this->salt; } /** * @inheritDoc */ public function getPassword() { return $this->password; } /** * @inheritDoc */ public function getRoles() { } /** * @inheritDoc */ public function eraseCredentials() { } /** * @see \Serializable::serialize() */ { $this->id, )); } /** * @see \Serializable::unserialize() */ { list ( $this->id, } public function isEqualTo(UserInterface $user) { return $this->id === $user->getId(); }
I mój UserRepository
// src/Backend/CmsBundle/Entity/UserRepository.php namespace Backend\CmsBundle\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; class UserRepository extends EntityRepository implements UserProviderInterface { public function loadUserByUsername($username) { $q = $this ->createQueryBuilder('u') ->where('u.username = :username OR u.email = :email') ->setParameter('username', $username) ->setParameter('email', $username) ->getQuery(); try { // The Query::getSingleResult() method throws an exception // if there is no record matching the criteria. $user = $q->getSingleResult(); } catch (NoResultException $e) { 'Unable to find an active admin BackendCmsBundle:User object identified by "%s".', $username ); throw new UsernameNotFoundException($message, 0, $e); } return $user; } public function refreshUser(UserInterface $user) { $class = get_class($user); if (!$this->supportsClass($class)) { throw new UnsupportedUserException( 'Instances of "%s" are not supported.', $class ) ); } return $this->find($user->getId()); } public function supportsClass($class) { return $this->getEntityName() === $class || is_subclass_of($class, $this->getEntityName()); }