public function errors(array $data, $newRecord = true)
    {
        $errors = [];

        foreach ($this->_fields as $name => $field) {
            $keyPresent = array_key_exists($name, $data);

            $providers = $this->_providers;
            $context = compact('data', 'newRecord', 'field', 'providers');

            if (!$keyPresent && !$this->_checkPresence($field, $context)) {
                $errors[$name]['_required'] = $this->getRequiredMessage($name);
                continue;
            }
            if (!$keyPresent) {
                continue;
            }

            $canBeEmpty = $this->_canBeEmpty($field, $context);

            $flags = static::EMPTY_ALL;
            if (isset($this->_allowEmptyFlags[$name])) {
                $flags = $this->_allowEmptyFlags[$name];
            }

            $isEmpty = $this->isEmpty($data[$name], $flags);

            if (!$canBeEmpty && $isEmpty) {
                $errors[$name]['_empty'] = $this->getNotEmptyMessage($name);
                continue;
            }

            if ($isEmpty) {
                continue;
            }

            $result = $this->_processRules($name, $field, $data, $newRecord);
            if ($result) {
                $errors[$name] = $result;
            }
        }

        return $errors;
    }
public function errors(array $data, $newRecord = true)
    {
        $errors = [];

        foreach ($this->_fields as $name => $field) {
            $keyPresent = array_key_exists($name, $data);

            $providers = $this->_providers;
            $context = compact('data', 'newRecord', 'field', 'providers');

            if (!$keyPresent && !$this->_checkPresence($field, $context)) {
                $errors[$name]['_required'] = $this->getRequiredMessage($name);
                continue;
            }
            if (!$keyPresent) {
                continue;
            }

            $canBeEmpty = $this->_canBeEmpty($field, $context);

            $flags = static::EMPTY_ALL;
            if (isset($this->_allowEmptyFlags[$name])) {
                $flags = $this->_allowEmptyFlags[$name];
            }

            $isEmpty = $this->isEmpty($data[$name], $flags);

            if (!$canBeEmpty && $isEmpty) {
                $errors[$name]['_empty'] = $this->getNotEmptyMessage($name);
                continue;
            }

            if ($isEmpty) {
                continue;
            }

            $result = $this->_processRules($name, $field, $data, $newRecord);
            if ($result) {
                $errors[$name] = $result;
            }
        }

        return $errors;
    }
public function errors ( array $ data , $ newRecord = true ) { $ errors = [ ] ; foreach ( $ this -> _fields as $ name => $ field ) { $ keyPresent = array_key_exists ( $ name , $ data ) ; $ providers = $ this -> _providers ; $ context = compact ( 'data' , 'newRecord' , 'field' , 'providers' ) ; if ( ! $ keyPresent && ! $ this -> _checkPresence ( $ field , $ context ) ) { $ errors [ $ name ] [ '_required' ] = $ this -> getRequiredMessage ( $ name ) ; continue ; } if ( ! $ keyPresent ) { continue ; } $ canBeEmpty = $ this -> _canBeEmpty ( $ field , $ context ) ; $ flags = static :: EMPTY_ALL ; if ( isset ( $ this -> _allowEmptyFlags [ $ name ] ) ) { $ flags = $ this -> _allowEmptyFlags [ $ name ] ; } $ isEmpty = $ this -> isEmpty ( $ data [ $ name ] , $ flags ) ; if ( ! $ canBeEmpty && $ isEmpty ) { $ errors [ $ name ] [ '_empty' ] = $ this -> getNotEmptyMessage ( $ name ) ; continue ; } if ( $ isEmpty ) { continue ; } $ result = $ this -> _processRules ( $ name , $ field , $ data , $ newRecord ) ; if ( $ result ) { $ errors [ $ name ] = $ result ; } } return $ errors ; }
Returns an array of fields that have failed validation. On the current model. This method will
actually run validation rules over data, not just return the messages.

@param array $data The data to be checked for errors
@param bool $newRecord whether the data to be validated is new or to be updated.
@return array Array of invalid fields
Returns an array of fields that have failed validation . On the current model . This method will actually run validation rules over data not just return the messages .