yii\base\Model::getFirstErrors PHP Метод

getFirstErrors() публичный Метод

Returns the first error of every attribute in the model.
См. также: getErrors()
См. также: getFirstError()
public getFirstErrors ( ) : array
Результат 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

Пример #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