FosUserbundle和symfony 2模板并进行编辑 [英] FosUserbundle and symfony 2 template and edits

查看:52
本文介绍了FosUserbundle和symfony 2模板并进行编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是symfony 2的新手.我刚刚安装了基本的FOSuserbundle.但是我有一些问题:

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

  1. 我已经设置了新的布局模板,但是找不到在哪里更改用于登录,注册,配置文件的表单模板

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

我找不到如何编辑用户个人资料.我可以使用/profile查看个人资料,但在那里找不到任何编辑链接

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

推荐答案

关于您的问题的答案,您可以在文档.这里有一些要点:

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

  1. 将要修改的模板从FOSUserBundle/Resources/views复制到捆绑软件中,然后进行所需的更改.
  2. 如果您需要创建自定义个人资料表单(根据我的问题,我猜是这样),那么您必须创建个人资料表单类型并指定FOSUserBundle使用它.
  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')
        ;
    }
}

这篇关于FosUserbundle和symfony 2模板并进行编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆