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

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

Returns the errors for all attributes or a single attribute.
См. также: getFirstErrors()
См. также: getFirstError()
public getErrors ( string $attribute = null ) : array
$attribute string attribute name. Use null to retrieve errors for all attributes.
Результат array errors for all attributes or the specified attribute. Empty array is returned if no error. Note that when returning errors for all attributes, the result is a two-dimensional array, like the following: ```php [ 'username' => [ 'Username is required.', 'Username must contain only word characters.', ], 'email' => [ 'Email address is invalid.', ] ] ```
    public function getErrors($attribute = null)
    {
        if ($attribute === null) {
            return $this->_errors === null ? [] : $this->_errors;
        } else {
            return isset($this->_errors[$attribute]) ? $this->_errors[$attribute] : [];
        }
    }

Usage Example

Пример #1
15
 /**
  * @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::getErrors