Yii2-verification rules, rules, judgment conditions, yii2-rules

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.