【问题标题】:FosUserbundle and symfony 2 template and editsFosUserbundle 和 symfony 2 模板和编辑
【发布时间】:2012-01-12 04:42:59
【问题描述】:

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

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

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

【问题讨论】:

    标签: php symfony fosuserbundle


    【解决方案1】:

    您可以在documentation 中找到有关您的问题的答案。以下是几点:

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

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

    【讨论】:

    • 谢谢你,但我什至找不到默认配置文件编辑的路由 URL。
    • vendor/bundles/FOS/UserBundle/Resources/config/routing/profile.xml里面
    【解决方案2】:

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

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

    正如@Anton 已经指出的那样,有关如何执行此操作的所有详细信息都在master documentationdocumentation for version 1.2.0 中(如果您使用的是 Symfony 2.0,您将需要它们。*

    【讨论】:

      猜你喜欢
      • 2018-02-26
      • 2013-02-17
      • 2016-03-23
      • 1970-01-01
      • 1970-01-01
      • 2016-05-09
      • 1970-01-01
      • 1970-01-01
      • 2015-05-22
      相关资源
      最近更新 更多