0
我試圖覆蓋FOSUserBundle默認註冊表單。確切地說,我試圖刪除用戶名。這個問題可能在services.yml中。但不確定。 services.yml文件:Symfony FOSUserBundle覆蓋表格
services:
user.registration.form.type:
class: Atotrukis\MainBundle\Form\Type\RegistrationFormType
tags:
- { name: form.type, alias: user_registration }
security.yml
security:
encoders:
FOS\UserBundle\Model\UserInterface: sha512
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
providers:
fos_userbundle:
id: fos_user.user_provider.username_email
firewalls:
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_provider: form.csrf_provider
logout: true
anonymous: true
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: ROLE_ADMIN }
RegistrationFormType.php
<?php
namespace Atotrukis\MainBundle\Form\Type;
use Symfony\Component\Form\FormBuilderInterface;
use FOS\UserBundle\Form\Type\RegistrationFormType as BaseType;
use Symfony\Component\Validator\Constraints as Assert;
class RegistrationFormType extends BaseType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
$builder->remove('username');
}
public function getName()
{
return 'user_registration';
}
}
?>
[這個線程可能給你一些更多的幫助]定義類(https://github.com/FriendsOfSymfony/FOSUserBundle/issues/555)。你使用1.3版還是2+版? [這也是一個精簡的文檔](https://github.com/FriendsOfSymfony/FOSUserBundle/blob/1.3.x/Resources/doc/logging_by_username_or_email.md),儘管它可能不會給你想要的東西 – sjagr 2014-10-29 13:05:50
我是使用Symfony 2.5.3和FOSUSerBundle 2.0 – Einius 2014-10-29 16:30:58