public function error($field, $text = null, array $options = [])
    {
        if (substr($field, -5) === '._ids') {
            $field = substr($field, 0, -5);
        }
        $options += ['escape' => true];

        $context = $this->_getContext();
        if (!$context->hasError($field)) {
            return '';
        }
        $error = $context->error($field);

        if (is_array($text)) {
            $tmp = [];
            foreach ($error as $k => $e) {
                if (isset($text[$k])) {
                    $tmp[] = $text[$k];
                } elseif (isset($text[$e])) {
                    $tmp[] = $text[$e];
                } else {
                    $tmp[] = $e;
                }
            }
            $text = $tmp;
        }

        if ($text !== null) {
            $error = $text;
        }

        if ($options['escape']) {
            $error = h($error);
            unset($options['escape']);
        }

        if (is_array($error)) {
            if (count($error) > 1) {
                $errorText = [];
                foreach ($error as $err) {
                    $errorText[] = $this->formatTemplate('errorItem', ['text' => $err]);
                }
                $error = $this->formatTemplate('errorList', [
                    'content' => implode('', $errorText)
                ]);
            } else {
                $error = array_pop($error);
            }
        }

        return $this->formatTemplate('error', ['content' => $error]);
    }
public function error($field, $text = null, array $options = [])
    {
        if (substr($field, -5) === '._ids') {
            $field = substr($field, 0, -5);
        }
        $options += ['escape' => true];

        $context = $this->_getContext();
        if (!$context->hasError($field)) {
            return '';
        }
        $error = $context->error($field);

        if (is_array($text)) {
            $tmp = [];
            foreach ($error as $k => $e) {
                if (isset($text[$k])) {
                    $tmp[] = $text[$k];
                } elseif (isset($text[$e])) {
                    $tmp[] = $text[$e];
                } else {
                    $tmp[] = $e;
                }
            }
            $text = $tmp;
        }

        if ($text !== null) {
            $error = $text;
        }

        if ($options['escape']) {
            $error = h($error);
            unset($options['escape']);
        }

        if (is_array($error)) {
            if (count($error) > 1) {
                $errorText = [];
                foreach ($error as $err) {
                    $errorText[] = $this->formatTemplate('errorItem', ['text' => $err]);
                }
                $error = $this->formatTemplate('errorList', [
                    'content' => implode('', $errorText)
                ]);
            } else {
                $error = array_pop($error);
            }
        }

        return $this->formatTemplate('error', ['content' => $error]);
    }
public function error ( $ field , $ text = null , array $ options = [ ] ) { if ( substr ( $ field , - 5 ) === '._ids' ) { $ field = substr ( $ field , 0 , - 5 ) ; } $ options += [ 'escape' => true ] ; $ context = $ this -> _getContext ( ) ; if ( ! $ context -> hasError ( $ field ) ) { return '' ; } $ error = $ context -> error ( $ field ) ; if ( is_array ( $ text ) ) { $ tmp = [ ] ; foreach ( $ error as $ k => $ e ) { if ( isset ( $ text [ $ k ] ) ) { $ tmp [ ] = $ text [ $ k ] ; } elseif ( isset ( $ text [ $ e ] ) ) { $ tmp [ ] = $ text [ $ e ] ; } else { $ tmp [ ] = $ e ; } } $ text = $ tmp ; } if ( $ text !== null ) { $ error = $ text ; } if ( $ options [ 'escape' ] ) { $ error = h ( $ error ) ; unset ( $ options [ 'escape' ] ) ; } if ( is_array ( $ error ) ) { if ( count ( $ error ) > 1 ) { $ errorText = [ ] ; foreach ( $ error as $ err ) { $ errorText [ ] = $ this -> formatTemplate ( 'errorItem' , [ 'text' => $ err ] ) ; } $ error = $ this -> formatTemplate ( 'errorList' , [ 'content' => implode ( '' , $ errorText ) ] ) ; } else { $ error = array_pop ( $ error ) ; } } return $ this -> formatTemplate ( 'error' , [ 'content' => $ error ] ) ; }
Returns a formatted error message for given form field, '' if no errors.

Uses the `error`, `errorList` and `errorItem` templates. The `errorList` and
`errorItem` templates are used to format multiple error messages per field.

### Options:

- `escape` boolean - Whether or not to html escape the contents of the error.

@param string $field A field name, like "modelname.fieldname"
@param string|array|null $text Error message as string or array of messages. If an array,
it should be a hash of key names => messages.
@param array $options See above.
@return string Formatted errors or ''.
@link https://book.cakephp.org/3.0/en/views/helpers/form.html#displaying-and-checking-errors
Returns a formatted error message for given form field if no errors .