[英]Allow null value but not allow empty String in Symfony
I have a case when i try to validate a property of an php PHP object, this property can be null but not empty string.我有一个案例,当我尝试验证 php PHP 对象的属性时,该属性可以为 null 但不能为空字符串。 Is it possible to do it with a single annotation like:是否可以使用单个注释来完成,例如:
class JustAnObject
{
/**
* @Assert\NotBlankNullable
*/
private $Property;
}
Yes it is possible in symfony 4.3 you can do:是的,在 symfony 4.3 中你可以这样做:
namespace App\Entity;
use Symfony\Component\Validator\Constraints as Assert;
class JustAnObject
{
/**
* @Assert\NotBlank(allowNull = true)
*/
private $property;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.