diff --git a/system/validation/error_collector.php b/system/validation/error_collector.php index 13285ce8..48fd8dbe 100644 --- a/system/validation/error_collector.php +++ b/system/validation/error_collector.php @@ -31,6 +31,17 @@ class Error_Collector { $this->messages[$attribute][] = $message; } + /** + * Determine if errors exist for an attribute. + * + * @param string $attribute + * @return bool + */ + public function has($attribute) + { + return $this->first($attribute) !== ''; + } + /** * Get the first error message for an attribute. * diff --git a/system/view.php b/system/view.php index 7a314211..0e93e51a 100644 --- a/system/view.php +++ b/system/view.php @@ -34,6 +34,16 @@ class View { { $this->view = $view; $this->data = $data; + + // ----------------------------------------------------- + // Every view has an error collector. This makes it + // convenient to check for any validation errors without + // worrying if the error collector is instantiated. + // + // If an error collector is in the session, it will + // be used as the error collector for the view. + // ----------------------------------------------------- + $this->data['errors'] = (Config::get('session.driver') != '' and Session::has('errors')) ? Session::get('errors') : new Validation\Error_Collector; } /**