yii\base\Model::hasErrors PHP Method

hasErrors() public method

Returns a value indicating whether there is any validation error.
public hasErrors ( string | null $attribute = null ) : boolean
$attribute string | null attribute name. Use null to check all attributes.
return boolean whether there is any error.
    public function hasErrors($attribute = null)
    {
        return $attribute === null ? !empty($this->_errors) : isset($this->_errors[$attribute]);
    }

Usage Example

 /**
  * @param Model $model
  * @param string $message
  * @param int $code
  * @param Exception $previous
  */
 public function __construct(Model $model, $message = null, $code = 0, Exception $previous = null)
 {
     $this->model = $model;
     if (is_null($message) && $model->hasErrors()) {
         $message = implode(' ', array_map(function ($errors) {
             return implode(' ', $errors);
         }, $model->getErrors()));
     }
     parent::__construct($message, $code, $previous);
 }
All Usage Examples Of yii\base\Model::hasErrors