我试图覆盖 FOSUserBundle 的唯一原因是我可以在构建表单时放置一个默认值,这样我就不会在加载表单时收到不适当的验证消息......
我正在关注文档。我已经投入Etienne/UserBundle/Form/Type/RegistrationFormType.php
<?php
namespace Etienne\UserBundle\Form\Type;
use Symfony\Component\Form\BaseType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use FOS\UserBundle\Form\Type\RegistrationFormType as BaseType;
class RegistrationFormType extends BaseType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('username', null, array('label' => 'form.username', 'translation_domain' => 'FOSUserBundle'))
->add('email', 'email', array('label' => 'form.email', 'translation_domain' => 'FOSUserBundle'))
->add('plainPassword', 'repeated', array(
'type' => 'password',
'options' => array('translation_domain' => 'FOSUserBundle'),
'first_options' => array('label' => 'form.password'),
'second_options' => array('label' => 'form.password_confirmation'),
'invalid_message' => 'fos_user.password.mismatch',
))
;
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => $this->class,
'intention' => 'registration',
));
}
public function getName()
{
return 'etienne_user_registration';
}
}
Etienne/UserBundle/Resources/config/services.yml
:
services:
etienne_user.registration.form.type:
class: Etienne\UserBundle\Form\Type\RegistrationFormType
arguments: [%fos_user.model.user.class%]
tags:
- { name: form.type, alias: etienne_user_registration }
并在app/config
:
FOS_User
registration:
form:
type: etienne_user_registration
我收到此错误消息:
/var/www/projet_etienne_auth/vendor/symfony/symfony/src/Symfony/Component/Form/FormRegistry.php 在第 95 行
if (!$type) {
throw new FormException(sprintf('Could not load type "%s"', $name));
}
$this->resolveAndAddType($type);