FOSUserBundle未进行验证
我在我的Bundle中创建了一个基于FOS UserBundle Model User BaseUser的User类来注册我的用户。
这是我的User.php:
class User extends BaseUser
{
/**
* @var integer
*
* @ORMColumn(name="id", type="integer")
* @ORMId
* @ORMGeneratedValue(strategy="AUTO")
*/
protected $id;
// Constructor
public function __construct()
{
parent::__construct();
// your own logic
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
}
这是我的UserType.php:
class UserType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('valider', 'submit')
;
}
/**
* @param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'CSW78BundleEntityUser'
));
}
public function getParent()
{
return 'fos_user_registration';
}
/**
* @return string
*/
public function getName()
{
return 'user';
}
}
我重写了register.html.twig,将它放在/ app / resources / FOSUserBundle / views / Registration中,并被调用。 这是我的register.html.twig:
{% block body %}
<div id="cadre" class="arrondi">
<h1>Inscription</h1>
<br>
{% block fos_user_content %}
<form action="{{ path('fos_user_registration_register') }}" {{ form_enctype(form) }} method="POST" class="fos_user_registration_register form-horizontal">
<div id="fos_user_registration_form">
<div class="form-group">
{{ form_label(form.username, 'Identifiant :', {'label_attr': {'class': 'col-xs-5 col-sm-4 col-md-3 col-lg-3 control-label'}}) }}
<div class="col-xs-7 col-sm-8 col-md-5 col-lg-5">
{{ form_widget(form.username, {'attr': {'class': 'form-control'}}) }}
</div>
</div>
<div class="form-group">
{{ form_label(form.email, 'Email :', {'label_attr': {'class': 'col-xs-5 col-sm-4 col-md-3 col-lg-3 control-label'}}) }}
<div class="col-xs-7 col-sm-8 col-md-5 col-lg-5">
{{ form_widget(form.email, {'attr': {'class': 'form-control'}}) }}
</div>
</div>
<div class="form-group">
{{ form_label(form.plainPassword.first, 'Mot de passe :', {'label_attr': {'class': 'col-xs-5 col-sm-4 col-md-3 col-lg-3 control-label'}}) }}
<div class="col-xs-7 col-sm-8 col-md-5 col-lg-5">
{{ form_widget(form.plainPassword.first, {'attr': {'class': 'form-control'}}) }}
</div>
</div>
<div class="form-group">
{{ form_label(form.plainPassword.second, 'Mot de passe (confirmation) :', {'label_attr': {'class': 'col-xs-5 col-sm-4 col-md-3 col-lg-3 control-label'}}) }}
<div class="col-xs-7 col-sm-8 col-md-5 col-lg-5">
{{ form_widget(form.plainPassword.second, {'attr': {'class': 'form-control'}}) }}
</div>
</div>
{{ form_widget(form._token, {'attr': {'class': 'form-control'}}) }}
{{ form_widget(form.valider, {'attr': {'class': 'btn btn-info btn-responsive btn-color'}}) }}
{{ form_end(form) }}
</div>
</form>
{% endblock %}
</div>
{% endblock %}
问题是我点击提交按钮时没有进行验证。
我认为验证约束会从BaseUser验证约束继承。
是否还有其他要指定的用于在我的用户对象上调用BaseUser验证约束?
另一个问题:如果我想自定义错误消息,我应该重写validation.xml文件来做到这一点吗?
谢谢。
大卫
链接地址: http://www.djcxy.com/p/91685.html