1

我是 symfony 2 的新手。我刚刚安装了基本的 FOSuserbundle。但我有几个问题:

  1. 我已经设置了新的布局模板,但我找不到在哪里更改登录、注册、个人资料的表单模板

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

4

2 回答 2

3

您可以在文档中找到有关您的问题的答案。这里有几点:

  1. 将您想要修改的模板复制FOSUserBundle/Resources/views到您的包中并进行您想要的更改。
  2. 如果您需要制作自定义配置文件表单(我根据您的问题猜测),那么您必须创建配置文件表单类型并指定 FOSUserBundle 使用它。

配置.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')
        ;
    }
}
于 2012-01-12T08:05:17.790 回答
2

@Anton 对您问题的第一部分有正确的答案,但要回答第二部分,如果您可以查看您的个人资料,/profile您可以通过/profile/edit在浏览器中进行编辑。

默认配置文件表单上没有编辑链接。如果需要,您需要听取@Anton 的建议并复制默认表单模板并将它们粘贴到捆绑包中具有相同名称的目录中。

正如@Anton 已经指出的那样,有关如何执行此操作的所有详细信息都在主文档版本 1.2.0 的文档中(如果您使用 Symfony 2.0,您将需要这些文档。*

于 2012-06-20T19:44:25.723 回答