IM
Size: a a a
IM
BS
AT
AT
when
range
A
yii\validators\Validator
A
AK
AT
AT
A
scenarios
можно не переопределять:
* The default implementation of this method will return all scenarios found in the [[rules()]]
* declaration. A special scenario named [[SCENARIO_DEFAULT]] will contain all attributes
* found in the [[rules()]]. Each scenario will be associated with the attributes that
* are being validated by the validation rules that apply to the scenario.
AT
A
scenarios
и убрать on
из rules
. Гибко, но не с первого раза въезжаешьAT
public function scenarios()
{
return [
self::SCENARIO_GUEST => ['email','username'],
self::SCENARIO_AUTH => ['user_id'],
];
}
public function rules()
{
return [
[ ['message','email','username'], 'required'],
[ ['message','email','username'], 'string'],
[ ['user_id'], 'integer']
];
}
A
A
A
scenarios
будут unsafe
A
'on'
у валидатора, либо пишешь метод scenarios
и указываешь в каких сценариях какие поля являются safe
A
AT