我有一个MyProject\SecurityBundle\Entity\User
带有验证约束的用户模型。对于我的注册,我创建了MyProject\SecurityBundle\Form\Model\Registration
:
namespace MyProject\SecurityBundle\Form\Model;
use MyProject\SecurityBundle\Entity\User;
class Registration
{
private $user;
private $termsAccepted;
public function setUser(User $user)
{
$this->user = $user;
return $this;
}
public function getUser()
{
return $this->user;
}
public function setTermsAccepted($termsAccepted)
{
$this->termsAccepted = (boolean)$termsAccepted;
return $this;
}
public function getTermsAccepted()
{
return $this->termsAccepted;
}
}
经验证:
MyProject\SecurityBundle\Form\Model\Registration:
properties:
user:
- Type: { type: MyProject\SecurityBundle\Entity\User }
termsAccepted:
- NotBlank: ~
getters:
termsAccepted:
- "True": ~
此验证有效,但用户实体的验证被此绕过。有没有办法可以将验证传输到我的注册模型中?