coolcsn / CsnUser

Authentication module using Doctrine
MIT License
33 stars 36 forks source link

Add new field in signup #39

Closed adarshkhatri closed 9 years ago

adarshkhatri commented 9 years ago

I am trying to add new input field in signup and edit user section.

However I am not sure where to add the form declaration for that field.

I have created a new column in user table, which is defined as FK.

Please help.

wingman007 commented 9 years ago

If you are using Doctrine it is a good idea to declare a new field and metadata for it in the model "User" I guess in this case. Notice: We are using the "Code first" approach by using Doctrine

  1. You don't create new fields in the table. You just add the new property in the class User (model). Yo also add all necessary metadata for this property in the very same file where User class lives.
  2. You run the doctrine-module tool to ask Doctrine to do its magic and add the field to your table by typing (on windows) vendor\bin\doctrine-module.bat list to see all commands. Chose the one for updating the schema. This will create a field for you.
  3. Make sure in your view you have few lines or a line to display the form field.
adarshkhatri commented 9 years ago

I see,

BTW when I declare form in view (phtml) file: $form->get('my_field')->setAttributes(array( 'required' => 'true', 'class' => 'form-control input-lg', ));

it throws an error. I have added a new entity file too.

Not sure if I try with your code first approach and run doctorine will fix this.

I will give this try tonight.

Thanks again.

adarshkhatri commented 9 years ago

This solved my requirement.