Welcome Guest, Not a member yet? Register   Sign In
When are the config_rules loaded for form_validation library?
#1

[eluser]amites[/eluser]
Hello,

I'm building a model to handle multiple groups of Form_Validation rules at once pulled from config/form_validation

my question is when are the rules loaded?
if I try to call them before run() the array is empty,

yet the run function inside form_validation doesn't show when they are loaded, they just show up within the first line of the function

is there any way to populate config_rules directly?
other approaches I'm not seeing?

thank you,
Alvin
#2

[eluser]Pascal Kriete[/eluser]
When a config file has the same name as a library, the config array is automatically passed to the library constructor.

To get them yourself you have two options.

1. Steal it from the library:
Code:
// Only works if the lib is loaded
$this->load->library('form_validation');
$rules = $this->form_validation->_config_rules;

2. Load it through the config library:
Code:
$this->config->load('form_validation', TRUE);
$rules = $this->config->item('form_validation');

Happy Holidays!
#3

[eluser]amites[/eluser]
went back over what you did, the load through config makes sense,

the "steal"ing version is similar to what I have going on

Code:
class MultiValid extends CI_Form_validation {

    function multi_rules($group = '') {
        
        $t = $this->_config_rules;
        if (is_array($t)) print_r($t);
            else echo 'nope';
            
        $set = false;
        if (is_array($group)) {
            foreach ($group as $grp) {
                if ($grp != '') {
                    
                    $this->set_rules($grp);
                    $set = true;
                }
            }
        }
        
        return $set;        
    }
}

echoes 'nope' every time after I load the form_validation library,
however from the first line of run _config has been populated,

I'm just wondering how I can force them to load earlier, no need to run multiple copies of an array like that (if I can avoid it)

thank you for your help




Theme © iAndrew 2016 - Forum software by © MyBB