views:

251

answers:

1

hello,

I succeeded to create a register form, and now users can register my site. But I can't create a form where users can edit their profile.

I have sf_guard_user and sf_guard_user_profile in my schema.yml

Does someone have an article about how to do that ? I tried few ideas without success.

+2  A: 

The quick way to start is to create a frontend CRUD with the task

./symfony doctrine:generate-crud ie.

./symfony doctrine:generate-crud frontend user sfGuardUser

(or you can just generate the profile form with the doctrine:build-forms task)

From here you can customize the form. The most tricky part will be merging the two forms, the sf_gurd_user_form (the one with the password and the username) and the sf_guard_profile_form. If you want profile fields and user fields on the same form you should use embedded forms as stated here:

http://www.blogs.uni-osnabrueck.de/rotapken/2009/03/13/symfony-merge-embedded-form/comment-page-1/

A snippet from that blog page:

class sfGuardUserForm extends BasesfGuardUserForm
{
  public function configure()
  {
    parent::configure();
    $profileForm = new UserProfileForm($this->object->Profile);
    unset ($profileForm['id'], $profileForm['sf_guard_user_id']);
    $this->embedForm("profile", $profileForm);
  }
}
gpilotino
+1 - i use the technique in the linked article regularly. just be aware that there are issues around post validators not getting copied over if you use the code as supplied.
benlumley