开发者

edit profile from frontend - symfony

开发者 https://www.devze.com 2022-12-10 18:49 出处:网络
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 开发者_StackOverflowtheir profile.

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 开发者_StackOverflowtheir 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.


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);
  }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消