您好,在管理系统上工作。我想在运行 @SecurityAssert\UserPassword之前运行验证约束“NotBlank” 。(否则会出现不需要的数据库命中,并且为用户提供两个不同的错误消息)这可能吗?谢谢!
use Symfony\Component\Security\Core\Validator\Constraints as SecurityAssert;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Constraints\NotBlank;
class YourClassName
/**
* @Assert\NotBlank( message = "For security reasons, please enter your current password.")
* @SecurityAssert\UserPassword(
* message = "Wrong value for your current password"
* )
*/
protected $oldPassword;
Run Code Online (Sandbox Code Playgroud)
正如 @Qoop 在他的评论中所说,使用如下例所示的序列组可以满足您的需求:
use Symfony\Component\Security\Core\Validator\Constraints as SecurityAssert;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Constraints\NotBlank;
/**
* @Assert\GroupSequence({"YourClassName", "After"})
*/
class YourClassName
/**
* @Assert\NotBlank(
message = "For security reasons, please enter your current password.")
* @SecurityAssert\UserPassword(
* message = "Wrong value for your current password",
groups={"After"}
* )
*/
protected $oldPassword;
Run Code Online (Sandbox Code Playgroud)
请记住在构建表单时添加这些验证组。
| 归档时间: |
|
| 查看次数: |
4179 次 |
| 最近记录: |