Yii2-verification rules, rules, judgment conditions, yii2-rules
I will not elaborate on the validation rules of the yii2 model for simple use. You can see what you want to see.
Official website tutorial
Http://www.yiichina.com/doc/guide/2.0/structure-models#validation-rules
Community netizen tutorial
Http://www.yiichina.com/topic/6420
Here I want to talk about the situation where conditions are added to the rules.
For example, if I want to implement at least one of the two fields is a required condition, then I need to add a judgment condition in required,
I have not written any documents in China before. The laravel framework has required_without to judge how to do this.
Later, I found the conditions for adding when and whenclient on stackoverflow. As mentioned above, after I found the relevant information on Google,
Baidu only found this article, but the relevant content was not detailed.
When indicates the judgment condition of the server and the effective condition.
Whenclient indicates the judgment condition of the client and the js validity condition.
The following is my code for reference only.
[ 'executor_id', 'required', 'when' => function ($model) { return empty($model->doctor_id); }, 'whenClient' => "function (attribute, value) { return $('#doctor_id').value == ''; }", 'on' => 'assgin', ], [ 'doctor_id', 'required', 'when' => function ($model) { return empty($model->executor_id); }, 'whenClient' => "function (attribute, value) { return $('#executor_id').value == ''; }", 'on' => 'assgin', ]
Conclusion: mastering advanced search technologies is very important for searching knowledge.