YII2 Model Validation Rule rules a rule validation failure immediately returns do not continue validating other fields
Mode::rules ();
Public Function Rules () {[ ' username ', ' password '], ' required '], [' age ', ' required '], //...}
Username returns error immediately, without verifying password and age. The same age if it's empty, it's not going to validate the other fields.
Do not know yii2 this piece have this kind of configuration?
Reply content:
YII2 Model Validation Rule rules a rule validation failure immediately returns do not continue validating other fields
Mode::rules ();
Public Function Rules () {[ ' username ', ' password '], ' required '], [' age ', ' required '], //...}
Username returns error immediately, without verifying password and age. The same age if it's empty, it's not going to validate the other fields.
Do not know yii2 this piece have this kind of configuration?
After the validation, I'll tell you which fields are not validated. See the code specifically.
/** * performs the data validation. * * This method executes the validation rules applicable to the current [[scenario]]. * The following criteria was used to determine whether a rule was currently applicable: * *-the rule must be Asso Ciated with the attributes relevant to the current scenario; *-The rules must is effective for the current scenario. * * This method would call [[[Beforevalidate ()]] and [[Aftervalidate ()]] before and * after the actual validation, R Espectively. If [[Beforevalidate ()]] returns FALSE, * the validation would be cancelled and [[Aftervalidate ()]] would not be called. * * Errors found during the validation can be retrieved via [[GetErrors ()]], * [[Getfirsterrors ()]] and [[GETF Irsterror ()]. * * @param array $attributeNames List of attribute names that should be validated. * If This parameter are empty, it means any attribute listed in the applicable * validation rules should be validated. * @param Boolean $clearErrors whether to call [[Clearerrors ()]] before performing validation * @return Boolean Wheth Er the validation is successful without any error. * @throws Invalidparamexception If the current scenario is unknown. */Public Function validate ($attributeNames = null, $clearErrors = True) {if ($clearErrors) {$th Is->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 foreach ($this->getactivevalidators () as $validator) {$validator->validate Attributes ($this, $attributeNames); } $this->aftervalidate (); Return! $this->haserrors (); }