CodeIgniter Forums
Validation set_rules doesn't make sense? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Validation set_rules doesn't make sense? (/showthread.php?tid=7577)



Validation set_rules doesn't make sense? - El Forum - 04-15-2008

[eluser]xwero[/eluser]
I never given it much though but the only thing the set_rules method does is copy the array you defined in the controller/model/library to a validation internal array. This means the method only wastes resources or am i missing something?

set_rules code
Code:
function set_rules($data, $rules = '')
    {
        if ( ! is_array($data))
        {
            if ($rules == '')
                return;
                
            $data[$data] = $rules;
        }
    
        foreach ($data as $key => $val)
        {
            $this->_rules[$key] = $val;
        }
    }

It may not be a big waste but in the meanwhile there are no parameters for the run method which is the method that uses the rules.


Validation set_rules doesn't make sense? - El Forum - 04-15-2008

[eluser]Pascal Kriete[/eluser]
When it comes down to it, you're right. It just copies. Interesting.

I like having a clean run method to be honest, why not make the _rules array public.


Validation set_rules doesn't make sense? - El Forum - 04-15-2008

[eluser]xwero[/eluser]
That is another good option. People should use class variables more instead of relying on methods.