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