yii\base\Model::getFirstErrors PHP Method

getFirstErrors() public method

Returns the first error of every attribute in the model.
See also: getErrors()
See also: getFirstError()
public getFirstErrors ( ) : array
return array the first errors. The array keys are the attribute names, and the array values are the corresponding error messages. An empty array will be returned if there is no error.
    public function getFirstErrors()
    {
        if (empty($this->_errors)) {
            return [];
        } else {
            $errors = [];
            foreach ($this->_errors as $name => $es) {
                if (!empty($es)) {
                    $errors[$name] = reset($es);
                }
            }
            return $errors;
        }
    }

Usage Example

Beispiel #1
0
 /**
  * @return array
  */
 public function getErrors()
 {
     if (empty($this->_errors)) {
         foreach ($this->_model->getFirstErrors() as $name => $message) {
             $this->_errors[] = ['field' => $name, 'message' => $message];
         }
     }
     return $this->_errors;
 }
All Usage Examples Of yii\base\Model::getFirstErrors