Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [SF][Symfony][Symfony3][S3] FOSUserBundle, + dodatkowe role przy rejestracji
umatik
post
Post #1





Grupa: Zarejestrowani
Postów: 209
Pomógł: 0
Dołączył: 17.05.2002
Skąd: lodz

Ostrzeżenie: (0%)
-----


W zasadzie mój problem opisuje temat. Jak mam dodać skutecznie dodatkowe pola w formularzu rejestracji
FOSUserBundle opisujące dodatkowe role np:

inputy standarowe:
- username
- email
- pass
- pass2

dodatkowe checkbox'y lub radio:
- role-wizard
- role-knight
- role-alien
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
kusiu
post
Post #2





Grupa: Zarejestrowani
Postów: 163
Pomógł: 10
Dołączył: 24.01.2006

Ostrzeżenie: (30%)
XX---


Cytat(umatik @ 7.12.2017, 10:03:55 ) *
W zasadzie mój problem opisuje temat. Jak mam dodać skutecznie dodatkowe pola w formularzu rejestracji
FOSUserBundle opisujące dodatkowe role np:

inputy standarowe:
- username
- email
- pass
- pass2

dodatkowe checkbox'y lub radio:
- role-wizard
- role-knight
- role-alien


User.php
  1. ...
  2. const ROLE_WIZARD = 'ROLE_WIZARD';
  3. const ROLE_KNIGHT = 'ROLE_KNIGHT';
  4. const ROLE_ALIEN = 'ROLE_ALIEN';
  5.  
  6. const ROLE_TO_DISPLAY = [
  7. self::ROLE_WIZARD => 'Wizard',
  8. self::ROLE_KNIGHT => 'Knight',
  9. self::ROLE_ALIEN => 'Alien',
  10. ];
  11.  
  12. public function getRole(): string
  13. {
  14. $roles = $this->getRoles();
  15. return current($roles);
  16. }
  17.  
  18. public function setRole(?string $role): self
  19. {
  20. return $this->setRoles([$role]);
  21. }


RegistrationFormType.php
  1. ...
  2. $builder->add('role', ChoiceType::class, [
  3. 'choices' => array_flip(User::ROLE_TO_DISPLAY),
  4. 'multiple' => false,
  5. 'expanded' => true,
  6. ]);
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 27.12.2025 - 13:08