artyomboyko
artyomboyko

Reputation: 2861

FOSUserBundle Entity constuct

I have entity User which extends FOSUserBundle.

class User extends BaseUser
{
...
    protected $ref_id;
    /**
     * @ORM\Column(type="float", length="11")
...

ref_id comes from cookies variable ref_id. How can i pass this value to entity User each times new user is registering. Do i have to override registerAction or create constructor on entity User and somehow pass ref_id there ?

Additionaly, i need to validate (check from database) ref_id every time new user is registering. How can i do that ?

    class User extends BaseUser
    {
    ...
       public function __construct()
       {
           $em = $this->getDoctrine()->getEntityManager();

This example doesn't work.

Upvotes: 2

Views: 340

Answers (1)

Mun Mun Das
Mun Mun Das

Reputation: 15002

You have to modify onSuccess method of RegistrationFormHandler class. Check Overriding Form Handlers section of the doc. In your overridden method you just have to add

$user->setRefId($this->request->cookies->get('ref_id'));

Right before calling the parent's onSuccess method.

As for validation you have to create custom validation constraint where you have to inject @request and @doctrine.orm.entity_manager services to get the cookie and validate it across the database. You can check this cookbook entry.

Upvotes: 3

Related Questions