Show
Ignore:
Timestamp:
02/25/2008 02:36:56 PM (9 months ago)
Author:
Shadowhand
Message:

Added Validation::load_errors($file), to provide a generic interface for loading error messages from language files.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/libraries/Validation.php

    r2159 r2169  
    473473 
    474474        /** 
     475         * Provides a generic interface to load the errors. Each field can have a 
     476         * specific message, such as username.required, and a default message, such 
     477         * as username.default. 
     478         * 
     479         * @param   string   language file to load errors from 
     480         * @return  void 
     481         */ 
     482        public function load_errors($file = 'forms') 
     483        { 
     484                foreach ($this->errors as $input => $error) 
     485                { 
     486                        // Key for this input error 
     487                        $key = "$file.$input.$error"; 
     488 
     489                        if (($str = Kohana::lang($key)) === $key) 
     490                        { 
     491                                // Get the default error message 
     492                                $str = Kohana::lang("$file.$input.default"); 
     493                        } 
     494 
     495                        // Add the message 
     496                        $this->message($input, $str); 
     497                } 
     498        } 
     499 
     500        /** 
    475501         * Rule: required. Generates an error if the field has an empty value. 
    476502         *