在我的實體,我有一個領域:Symfony的3:GroupSequence在validation_groups
/**
* @Assert\Regex("/^[a-z0-9-]+$/", groups={"Basic1"})
* @Assert\Regex("/^[a-z0-9]+[a-z0-9-]*[a-z0-9]+$/", groups={"Basic2"})
* @AppAssert\SaveDomain(groups={"Registration"})
*/
protected $myField;
我想驗證的順序領域:Basic1,Basic2,登記。
當我使用GroupSequence類註釋:
/**
* @Assert\GroupSequence({"MyEntity", "Basic1", "Basic2", "Registration"})
*/
class MyEntity
{
它按預期工作,Basic1 => Basic2 =>註冊:
但我需要使用validation_groups以及...當我在Type類中指定它,GroupSequence不再工作。
我嘗試直接在validation_groups使用GroupSequence但像它說這裏似乎不工作:https://github.com/symfony/symfony/pull/10287
$form = $this->createForm(new BlogType(), new Blog(), [
'validation_groups' => new GroupSequence(['Basic', 'Strict']),
]);
但是我把它變成Type類爲configureOptions:
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => 'AppBundle\Entity\MyEntyty',
'validation_groups' => new GroupSequence(['Basic1', 'Basic2', 'Registration']),
]);
}
有人知道我怎樣才能同時使用GroupSequence和validation_groups?
我發現現在唯一的解決辦法是specificly創建自定義驗證此字段...
我已經這樣做了,但是當我在類Type中添加validation_groups時,它不再工作。 – Atyz