$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.
Please login to continue.