如何使用\ Symfony \ Component \ Validator \ Constraints \ EqualTo比较实体的两个不同属性以检查它们是否相等?
答案 0 :(得分:1)
您可以使用Expression validator检查实体的两个不同属性是否相等:
// src/AppBundle/Model/MyEntity.php
namespace AppBundle\Model;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @Assert\Expression(
* "this.getFirstProperty() == this.getSecondProperty()",
* message="The first and second properties must be equal!"
* )
*/
class MyEntity
{
private firstProperty;
private secondProperty;
public function getFirstProperty()
{
return $this->firstProperty;
}
public function getSecondProperty()
{
return $this->secondProperty;
}
}
我认为\ Symfony \ Component \ Validator \ Constraints \ EqualTo不可能。