validators\Validator $when

$when public property

A PHP callable whose return value determines whether this validator should be applied. The signature of the callable should be function ($model, $attribute), where $model and $attribute refer to the model and the attribute currently being validated. The callable should return a boolean value.

This property is mainly provided to support conditional validation on the server-side. If this property is not set, this validator will be always applied on the server-side.

The following example will enable the validator only when the country currently selected is USA:

function ($model) {
    return $model->country == Country::USA;
}

See also $whenClient.

public callable $when = null
doc_Yii
2016-10-30 17:14:16
Comments
Leave a Comment

Please login to continue.