php - FOSUserBundle (Symfony2). I have some questions -


1) How can I add new fields and registration actions to the table (show new fields on the reged page)? For example: I want to add new fields last_name, age

2) I added a new listener for REGISTRATION_COMPLETED

/src/Acme/UserBundle/EventListener/RegistrationCompletedListener.php:

  & lt ;? Php namespace Acme \ UserBundle \ EventListener; Use FOS \ UserBundle \ FOSUserEvents; Use FOS \ UserBundle \ Event \ FormEvent; Use Symfony \ Component \ EventDispatcher \ EventSubscriberInterface; Use Symfony \ Component \ HttpFoundation \ RedirectResponse; Use Symfony \ Component \ Routing \ Generator \ UrlGeneratorInterface; / ** * Listener * / Class Registration Completion Event Subscriber Interface {Private $ router; Public function __ composition (UrlGeneratorInterface $ Router) {$ this- & gt; Router = $ router; } / ** * {@ Inherit Doc} * / Public Static Function getSubscribedEvents () {Return Array (FOSUserEvents :: REGISTRATION_COMPLETED = & gt; 'onRegistrationCompletedSuccess');); } Registered success on public functions (event event event) {$ url = $ this- & gt; Router- & gt; Generation ('Home'); $ Event- & gt; Set Response (new redirection response ($ url)); }}   

/src/Acme/UserBundle/Resources/config/services.yml: Services: acme_user.registration_completed : Category: Acme \ UserBundle \ EventListener \ RegistrationCompletedListener Logic: [@router] Tags: - {name: kernel.event_subscriber}

Why not work?

1) You must expand the base user class and there your new The fields must be added, such as:

  namespaces in your custombundle \ unit; Use FOS \ UserBundle \ Model \ User as BaseUser; Use the principle / ORM \ mapping as ORM; / ** * User * * @ORM \ Table (name = "fos_user") * Expands / Class User BaseUser {/ ** * @Wer String * * @ORM \ Columns (name = "first_name", type = "String", length = 255) * / private $ firstName; / ** * @ string string * * @ORM \ column (name = "last_name", type = "string", length = 255) * / personal $ lastName; }   

and update appconfig / config.yml :

  #FOSLUserBundle configuration fos_user: user_class: Your \ CustomBundle \ Entity   

Then you need to increase and configure the new registration form. Here's how you can do it.

[edit]:

2)

Create an event listener like this: Name Location Your Bundle \ EventListener; Use FOS \ UserBundle \ Event \ FilterUserResponseEvent; Class UserListener {Registration complete on Public Function (FilterUserResponseEvent $ event) {$ user = $ event- & gt; GetUser (); // do sth ....}}

and register service for:

  Services: some_name.security.registration_listener: Category: Your \ Bundle \ EventListener \ UserListener Tags: - {Name: kernel.event_listener, Event: fos_user.registration.completed, Method: onRegistrationCompleted}    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -