Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [Symfony][SF2][Symfony2]Doctrine Entity Provider
Forum PHP.pl > Forum > PHP
gentleman
Witam, chciałbym załadować uzytkowników do logowania, ale podczas generowania entity wyrzuca bład.

  1. <?php
  2. namespace Acme\AccountBundle\Entity;
  3.  
  4. use Symfony\Component\Security\Core\User\UserInterface;
  5. use Doctrine\ORM\Mapping as ORM;
  6.  
  7. /*
  8.  * @ORM\Entity
  9.  */
  10. class User implements UserInterface
  11. {
  12. /**
  13.   * @ORM\Id
  14.   * @ORM\Column(type="integer")
  15.   * @ORM\GeneratedValue(strategy="AUTO")
  16.   */
  17. protected $id;
  18. /**
  19.   * @ORM\Column(type="string", length="100")
  20.   */
  21. protected $username;
  22. /**
  23.   * @ORM\Column(type="string", length="255")
  24.   */
  25. protected $password;
  26. /**
  27.   * @ORM\Column(type="string", length="20")
  28.   */
  29. protected $role;
  30. /**
  31.   * @ORM\Column(type="string", length="32")
  32.   */
  33. protected $salt;
  34.  
  35. }


bład.
Kod
Fatal error: Class Acme\AccountBundle\Entity\User contains 5 abstract methods and must therefore be declared abstract or implement the remaining methods (Symfony\Component\Security\Core\User\UserInterface::getRoles, Symfony\Component\Security\Core\User\UserInterface::getPassword, Symfony\Component\Security\Core\User\UserInterface::getSalt, ...) in /workspace/symfony-test/src/Acme/AccountBundle/Entity/User.php on line 35

nie rozumiem o co chodzi, wytłumaczy mi ktoś ?
Crozin
Absolutne podstawy PHP - interfejsy: http://php.net/manual/en/language.oop5.interfaces.php - błąd nie ma nic wspólnego z Symfony.
gentleman
ok ale nadal koledzy mam problem z logowaniem użytkowników. Gdy używam
użytkowników z "pamięci" jest wszystko dobrze jednak gdy próbuje
załadować użytkowników z bazy wychodzą błędy. Postępuje
raczej zgonie z dokumentacją symfony2.

security.yml
  1. jms_security_extra:
  2. secure_all_services: false
  3. expressions: true
  4.  
  5. security:
  6. encoders:
  7. Symfony\Component\Security\Core\User\User: plaintext
  8.  
  9. role_hierarchy:
  10. ROLE_ADMIN: ROLE_USER
  11. ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN,
  12. ROLE_ALLOWED_TO_SWITCH]
  13.  
  14. providers:
  15. main:
  16. entity: { class: Acme\AccountBundle\Entity\User,
  17. property: username }
  18.  
  19. firewalls:
  20. dev:
  21. pattern: ^/(_(profiler|wdt)|css|images|js)/
  22. security: false
  23.  
  24. login:
  25. pattern: ^/secured/login$
  26. security: false
  27.  
  28. secured_area:
  29. pattern: ^/secured/
  30. form_login:
  31. check_path: _ServiceLogin_Check
  32. login_path: _ServiceLogin
  33. always_use_default_target_path: true
  34. default_target_path: /index
  35.  
  36. logout:
  37. path: _demo_logout
  38. target: _demo
  39. #anonymous: ~
  40. #http_basic:
  41. # realm: "Secured Demo Area"
  42.  
  43. access_control:
  44. - { path: ^/secured/login, roles:
  45. IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }


user.php
  1. <?php
  2. // src/Acme/UserBundle/Entity/User.php
  3. namespace Acme\AccountBundle\Entity;
  4.  
  5. use Symfony\Component\Security\Core\User\UserInterface;
  6.  
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9.  
  10. /**
  11.  * Acme\AccountBundle\Entity\User
  12.  *
  13.  * @ORM\Table(name="users")
  14.  * @ORM\Entity(repositoryClass="Acme\AccountBundle\Entity\Users") // za bardzo od czego to jest :( wiec przypisalem do entity users
  15.  */
  16. class User implements UserInterface
  17. {
  18. /**
  19. * @ORM\Column(type="integer")
  20. * @ORM\Id
  21. * @ORM\GeneratedValue(strategy="AUTO")
  22. */
  23. private $id;
  24.  
  25. /**
  26. * @ORM\Column(type="string", length=255, unique=true)
  27. */
  28. private $username;
  29.  
  30. /**
  31. * @ORM\Column(type="string", length=255)
  32. */
  33. private $salt;
  34.  
  35. /**
  36. * @ORM\Column(type="string", length=255)
  37. */
  38. private $password;
  39.  
  40. /**
  41. * @ORM\Column(type="string", length=255, unique=true)
  42. */
  43. private $email;
  44.  
  45. /**
  46. * @ORM\Column(name="is_active", type="boolean")
  47. */
  48. private $isActive;
  49.  
  50. public function __construct()
  51. {
  52. $this->isActive = true;
  53. $this->salt = md5(uniqid(null, true));
  54. }
  55.  
  56. /**
  57. * @inheritDoc
  58. */
  59. public function getUsername()
  60. {
  61. return $this->username;
  62. }
  63.  
  64. /**
  65. * @inheritDoc
  66. */
  67. public function getSalt()
  68. {
  69. return $this->salt;
  70. }
  71.  
  72. /**
  73. * @inheritDoc
  74. */
  75. public function getPassword()
  76. {
  77. return $this->password;
  78. }
  79.  
  80. /**
  81. * @inheritDoc
  82. */
  83. public function getRoles()
  84. {
  85. return array('ROLE_USER');
  86. }
  87.  
  88. /**
  89. * @inheritDoc
  90. */
  91. public function eraseCredentials()
  92. {
  93. }
  94.  
  95. /**
  96. * @see \Serializable::serialize()
  97. */
  98. public function serialize()
  99. {
  100. return serialize(array(
  101. $this->id,
  102. ));
  103. }
  104.  
  105. /**
  106. * @see \Serializable::unserialize()
  107. */
  108. public function unserialize($serialized)
  109. {
  110. list (
  111. $this->id,
  112. ) = unserialize($serialized);
  113. }
  114.  
  115. /**
  116. * Get id
  117. *
  118. * @return integer
  119. */
  120. public function getId()
  121. {
  122. return $this->id;
  123. }
  124.  
  125. /**
  126. * Set username
  127. *
  128. * @param string $username
  129. * @return User
  130. */
  131. public function setUsername($username)
  132. {
  133. $this->username = $username;
  134.  
  135. return $this;
  136. }
  137.  
  138. /**
  139. * Set salt
  140. *
  141. * @param string $salt
  142. * @return User
  143. */
  144. public function setSalt($salt)
  145. {
  146. $this->salt = $salt;
  147.  
  148. return $this;
  149. }
  150.  
  151. /**
  152. * Set password
  153. *
  154. * @param string $password
  155. * @return User
  156. */
  157. public function setPassword($password)
  158. {
  159. $this->password = $password;
  160.  
  161. return $this;
  162. }
  163.  
  164. /**
  165. * Set email
  166. *
  167. * @param string $email
  168. * @return User
  169. */
  170. public function setEmail($email)
  171. {
  172. $this->email = $email;
  173.  
  174. return $this;
  175. }
  176.  
  177. /**
  178. * Get email
  179. *
  180. * @return string
  181. */
  182. public function getEmail()
  183. {
  184. return $this->email;
  185. }
  186.  
  187. /**
  188. * Set isActive
  189. *
  190. * @param boolean $isActive
  191. * @return User
  192. */
  193. public function setIsActive($isActive)
  194. {
  195. $this->isActive = $isActive;
  196.  
  197. return $this;
  198. }
  199.  
  200. /**
  201. * Get isActive
  202. *
  203. * @return boolean
  204. */
  205. public function getIsActive()
  206. {
  207. return $this->isActive;
  208. }
  209. }



kawałek users.php
  1. namespace Acme\AccountBundle\Entity;
  2.  
  3. use Doctrine\ORM\Mapping as ORM;
  4.  
  5. /**
  6.  * @ORM\Entity
  7.  * @ORM\Table(name="users")
  8.  */
  9. class Users
  10. {
  11. /**
  12. * @ORM\Id
  13. * @ORM\Column(type="integer")
  14. * @ORM\GeneratedValue(strategy="AUTO")
  15. */
  16. protected $id;
  17.  
  18. /**
  19. * @ORM\Column(type="string", length=255)
  20. */
  21. protected $email;
  22.  
  23. /**
  24. * @ORM\Column(type="string", length=255)
  25. */
  26. protected $username;
  27.  
  28. /**
  29. * @ORM\Column(type="string", length=255)
  30. */
  31. protected $location;
  32.  
  33. /**
  34. * @ORM\Column(type="string", length=255)
  35. */
  36. protected $name;
  37.  
  38. /**
  39. * @ORM\Column(type="string", length=255)
  40. */
  41. protected $password;
  42.  
  43. /**
  44. * @ORM\Column(type="integer")
  45. */
  46. protected $role;
  47.  
  48. //...
  49. }

Nie wiem co zrobiłem źle, jestem początkujący. W dokumentacji pisze że wystarczy zrobić klasę np User i skonfigurowac security.yml W zend2 nie mialem takich problemow z logowaniem.
pyro
Jeżeli to ten sam błąd to czytaj go aż do bólu:

Cytat
Fatal error: Class Acme\AccountBundle\Entity\User contains 5 abstract methods and must therefore be declared abstract or implement the remaining methods (Symfony\Component\Security\Core\User\UserInterface::getRoles, Symfony\Component\Security\Core\User\UserInterface::getPassword, Symfony\Component\Security\Core\User\UserInterface::getSalt, ...) in /workspace/symfony-test/src/Acme/AccountBundle/Entity/User.php on line 35


Jak nie znasz angielskiego - przetłumacz.
gentleman
wcześniejszy błąd już rozwiązałem. Dlaczego w dokumentacji ponoć działa a jak ja to robie to nie?
pyro
Przynajmniej napisałeś, że wyskakują Ci jakieś błędy, ale dostawa fusów do wróżenia ostatnio nie dociera, więc może być ciężko je odgadnąć.

// EDIT

Poza tym wcześniejszych błędów wcale nie naprawiłeś, tylko je bardzo brzydko ominąłeś (przynajmniej w podanym tutaj kodzie), ale to już inna sprawa.
gentleman
error.
Kod
FatalErrorException: Error: Call to undefined method Acme\AccountBundle\Entity\Users::findOneBy() in /workspace/forum-project/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php line 55
pyro
A widzisz w tym Entity taką metodę jak findOneBy? W entities nie ma metod repozytorium. Jeszcze nie dołączyłeś kodu jak to wywołujesz.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.