我有一些字段的实体,例如名称和名称有验证组:
<?php
namespace RFQ\IronilBundle\Entity;
use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
* @ORM\Table(name="users")
* @ORM\HasLifecycleCallbacks
*/
class User extends BaseUser {
/**
* @ORM\Column(type="string", length=50)
* @Assert\NotBlank(groups={"qqq"})
*/
protected $name;
我的FormType:
public function buildForm(FormBuilderInterface $builder, array $options) {
$this->buildUserForm($builder, $options);
$builder->add('name', null, array(
'label' => 'Name',
'attr' => array(
'class' =>'form-control',
'placeholder' =>'Name'
)));
}
public function setDefaultOptions(OptionsResolverInterface $resolver) {
$resolver->setDefaults(array(
'data_class' => $this->class,
'intention' => 'profile',
'validation_groups' => array('qqq')
));
}
问题是我的验证组'qqq'不起作用,我可以提交带有空名称输入的表单。在Symfony中,文档说验证组可以像我一样通过setDefaultOptions方法,但它只是不起作用。我错过了什么?
谢谢!
修改 经过一些测试,我可以说只有'默认'验证组,而不是我的'qqq'。