FosUserbundle and symfony 2 template and edits

血红的双手。 提交于 2019-12-19 04:42:28

问题


I am new to symfony 2. I have just setup with basic FOSuserbundle. But I have a few problems:

  1. I have setup the new layout template but I could not find where to change the form template for login, registration, profile

  2. I could not find how to edit the user profile. I can view the profile using /profile but I could not find any edit link there


回答1:


Answers on your questions you can find inside documentation. Here are some points:

  1. Copy templates you want to modify from FOSUserBundle/Resources/views into your bundle and do changes you want.
  2. If you need to make a custom profile form (as I guess based on your question), then you have to create profile form type and specify that FOSUserBundle uses it.

config.yml

services:
  my_user.profile.form.type:
    class: My\UserBundle\Form\Type\ProfileFormType
    arguments: [%fos_user.model.user.class%]
    tags:
        - { name: form.type, alias: my_user_profile }

fos_user:
  profile:
    form:
      type: my_user_profile

ProfileFormType.php

<?php

namespace My\UserBundle\Form\Type;

use Symfony\Component\Form\FormBuilder;
use FOS\UserBundle\Form\Type\ProfileFormType as BaseType;

class ProfileFormType extends BaseType
{

    public function getName()
    {
        return 'my_user_profile';
    }

    protected function buildUserForm(FormBuilder $builder, array $options)
    {
        $builder
        ->add('email', 'email')
        ->add('firstName')
        ->add('lastName')
        ;
    }
}



回答2:


@Anton has the correct answer for the first part of your question but to answer the second part, if you can view your profile from /profile you can edit by going to /profile/edit in your browser.

There is no edit link on the default profile form. If you want one, you'll need to take the advice of @Anton and copy the default form template(s) and paste them into a directory with the same name in your bundle.

As @Anton already pointed out, all of the details on how to do this are in either the master documentation or the documentation for version 1.2.0 (which you will need if you are using Symfony 2.0.*



来源:https://stackoverflow.com/questions/8830233/fosuserbundle-and-symfony-2-template-and-edits

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!