Yii2model verification rule rules: a rule verification failure immediately returns not to continue to verify other fields Mode: rules (); {code ...} if username is null, an error is returned immediately. password and age are not verified. Similarly, if age is empty, other fields will not be verified. if yii2 is not known, this... yii2 model verification rule rules, a rule verification failure will be returned immediately. if other fields are not verified
Mode: rules ();
public function rules(){ [['username', 'password'], 'required'], ['age', 'required'], // ......}
If username is null, an error is returned immediately. password and age are not verified. Similarly, if age is empty, other fields are not verified.
I don't know if yii2 has such configuration?
Reply content:
Yii2 model verification rule rules: one rule fails to be verified. immediate return does not continue to verify other fields
Mode: rules ();
public function rules(){ [['username', 'password'], 'required'], ['age', 'required'], // ......}
If username is null, an error is returned immediately. password and age are not verified. Similarly, if age is empty, other fields are not verified.
I don't know if yii2 has such configuration?
After verification, tell you which fields have not passed verification. For more information, see the code.
/*** Performs the data validation. ** This method executes the validation rules applicable to the current [[scenario]. * The following criteria are used to determine whether a rule is currently applicable: **-the rule must be associated with the attributes relevant to the current scenario; *-the rules must be valid tive for the current scenario. ** This method will call [[beforeValidate ()] And [[afterValidate ()] before and * after the actual validation, respectively. if [[beforeValidate ()] returns false, * the validation will be canceled and [[afterValidate ()] will not be called. ** Errors found during the validation can be retrieved via [[getErrors ()], * [[getFirstErrors ()] and [[getFirstError ()]. ** @ param array $ attributeNames list of attribute names that shocould be vali Dated. * If this parameter is empty, it means any attribute listed in the applicable * validation rules shoshould be validated. * @ param boolean $ clearErrors whether to call [[clearErrors ()] before validation * @ return boolean whether the validation is successful without any error. * @ throws InvalidParamException if the current scenario is unknown. */public function validate ($ attributeNa Mes = null, $ clearErrors = true) {if ($ clearErrors) {$ this-> clearErrors ();} if (! $ This-> beforeValidate () {return false;} $ scenarios = $ this-> scenarios (); $ scenario = $ this-> getScenario (); if (! Isset ($ scenarios [$ scenario]) {throw new InvalidParamException ("Unknown scenario: $ scenario");} if ($ attributeNames = null) {$ attributeNames = $ this-> activeAttributes ();} // note this foreach ($ this-> getActiveValidators () as $ validator) {$ validator-> validateAttributes ($ this, $ attributeNames);} $ this-> afterValidate (); return! $ This-> hasErrors ();}