public function setErrors(array $fields, $overwrite = false)
    {
        if ($overwrite) {
            foreach ($fields as $f => $error) {
                $this->_errors[$f] = (array)$error;
            }

            return $this;
        }

        foreach ($fields as $f => $error) {
            $this->_errors += [$f => []];

            // String messages are appended to the list,
            // while more complex error structures need their
            // keys preserved for nested validator.
            if (is_string($error)) {
                $this->_errors[$f][] = $error;
            } else {
                foreach ($error as $k => $v) {
                    $this->_errors[$f][$k] = $v;
                }
            }
        }

        return $this;
    }
public function setErrors(array $fields, $overwrite = false)
    {
        if ($overwrite) {
            foreach ($fields as $f => $error) {
                $this->_errors[$f] = (array)$error;
            }

            return $this;
        }

        foreach ($fields as $f => $error) {
            $this->_errors += [$f => []];

            // String messages are appended to the list,
            // while more complex error structures need their
            // keys preserved for nested validator.
            if (is_string($error)) {
                $this->_errors[$f][] = $error;
            } else {
                foreach ($error as $k => $v) {
                    $this->_errors[$f][$k] = $v;
                }
            }
        }

        return $this;
    }
public function setErrors ( array $ fields , $ overwrite = false ) { if ( $ overwrite ) { foreach ( $ fields as $ f => $ error ) { $ this -> _errors [ $ f ] = ( array ) $ error ; } return $ this ; } foreach ( $ fields as $ f => $ error ) { $ this -> _errors += [ $ f => [ ] ] ; // String messages are appended to the list, // while more complex error structures need their // keys preserved for nested validator. if ( is_string ( $ error ) ) { $ this -> _errors [ $ f ] [ ] = $ error ; } else { foreach ( $ error as $ k => $ v ) { $ this -> _errors [ $ f ] [ $ k ] = $ v ; } } } return $ this ; }
Sets error messages to the entity

## Example

```
// Sets the error messages for multiple fields at once
$entity->setErrors(['salary' => ['message'], 'name' => ['another message']]);
```

@param array $fields The array of errors to set.
@param bool $overwrite Whether or not to overwrite pre-existing errors for $fields
@return $this
Sets error messages to the entity