NotNull
验证值不严格等于 null。要确保值不为空(不是空字符串),请参阅 NotBlank 约束。
| 应用于 | 属性或方法 |
| 类 | NotNull |
| 验证器 | NotNullValidator |
基本用法
如果您想确保 Author 类的 firstName 属性不严格等于 null,您将
1 2 3 4 5 6 7 8 9 10
// src/Entity/Author.php
namespace App\Entity;
use Symfony\Component\Validator\Constraints as Assert;
class Author
{
#[Assert\NotNull]
protected string $firstName;
}
这项工作,包括代码示例,均根据 Creative Commons BY-SA 3.0 许可获得许可。