base\Model validate()

validate() public method

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 effective 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 cancelled and afterValidate() will not be called.

Errors found during the validation can be retrieved via getErrors(), getFirstErrors() and getFirstError().

public boolean validate ( $attributeNames = null, $clearErrors = true )
$attributeNames array

List of attribute names that should be validated. If this parameter is empty, it means any attribute listed in the applicable validation rules should be validated.

$clearErrors boolean

Whether to call clearErrors() before performing validation

return boolean

Whether the validation is successful without any error.

throws yii\base\InvalidParamException

if the current scenario is unknown.

doc_Yii
2016-10-30 16:51:57
Comments
Leave a Comment

Please login to continue.