IsNull

Validates that a value is exactly equal to null. To force that a property is blank (blank string or null), see the Blank constraint. To ensure that a property is not null, see NotNull.

値が null と正確に等しいことを検証します。プロパティを強制的に空白 (空白の文字列または null) にするには、Blank 制約を参照してください。プロパティが null でないことを確認するには、NotNull を参照してください。

Also see NotNull.

NotNull も参照してください。
Applies to property or method
Class IsNull
Validator IsNullValidator

Basic Usage

If, for some reason, you wanted to ensure that the firstName property of an Author class exactly equal to null, you could do the following:

何らかの理由で、Author クラスの firstName プロパティが null と正確に等しいことを確認したい場合は、次のようにすることができます。
  • Attributes
    属性
  • YAML
    YAML
  • XML
    XML
  • PHP
    PHP
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\IsNull]
    protected $firstName;
}

Options

groups

type: array | string

タイプ: 配列 |ストリング

It defines the validation group or groups of this constraint. Read more about validation groups.

この制約の検証グループを定義します。検証グループの詳細を参照してください。

message

type: string default: This value should be null.

タイプ: 文字列 デフォルト: この値は null にする必要があります。

This is the message that will be shown if the value is not null.

これは、値が null でない場合に表示されるメッセージです。

You can use the following parameters in this message:

このメッセージでは、次のパラメーターを使用できます。
Parameter Description
{{ value }} The current (invalid) value
{{ label }} Corresponding form field label

payload

type: mixed default: null

タイプ: 混合 デフォルト: null

This option can be used to attach arbitrary domain-specific data to a constraint. The configured payload is not used by the Validator component, but its processing is completely up to you.

このオプションは、任意のドメイン固有のデータを制約に添付するために使用できます。構成されたペイロードは Validator コンポーネントによって使用されませんが、その処理は完全にユーザー次第です。

For example, you may want to use several error levels to present failed constraints differently in the front-end depending on the severity of the error.

たとえば、いくつかのエラー レベルを使用して、エラーの重大度に応じて、失敗した制約をフロントエンドで異なる方法で提示することができます。