![]() |
Problems loading validation rules in config file - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Problems loading validation rules in config file (/showthread.php?tid=26411) |
Problems loading validation rules in config file - El Forum - 01-13-2010 [eluser]built2fall[/eluser] Hello, I'm new to CodeIgniter and very much liking it so far, however I've run into a problem. I'm having difficulty getting my validation rules to load automatically from file by associating a controller function with a rule group. Following the Saving Sets of Validation Rules to a Config File, I placed my form validation rules within a file named form_validation.php in application/configs. However, no validation errors are being printed out by validation_errors(). I have tried making a specific rule group and inserting as a parameter to form_validation->run(), but I get the same result. However, If I set the rules manually in the controller file using set_rules() it works properly. Anyone have any advice? Here is my code: Controller: controllers/signup.php Code: <?php View: views/auth/signup.php Code: <?php doctype('xhtml1-strict'); ?> Validation Rules: config/form_validation.php Code: <?php Problems loading validation rules in config file - El Forum - 01-13-2010 [eluser]flaky[/eluser] Code: if ($this->form_validation->run('signup/index') == FALSE) Problems loading validation rules in config file - El Forum - 01-13-2010 [eluser]built2fall[/eluser] EDIT: scratch that, still not working. Problems loading validation rules in config file - El Forum - 01-13-2010 [eluser]nkm82[/eluser] Are you auto-loading the library? If not, you must explicitly load it at the controller. Code: $this->load->library('form_validation'); Problems loading validation rules in config file - El Forum - 01-13-2010 [eluser]built2fall[/eluser] It was being loaded in a custom library (which itself was auto loaded). Tried loading explicitly in the controller, same result. And just to reiterate it works if I explicitly set the rules in the controller: Code: $config = array( EDIT: I guess I'll just settle for making the validation rules a config file and autoload it. Followed by adding the following line to index() Code: $this->form_validation->set_rules($this->config->item('signup', 'validation_rules')); Problems loading validation rules in config file - El Forum - 01-17-2010 [eluser]ekevin[/eluser] Hi, I've just had the same problem, following this topic I put Code: $this->form_validation->run('[b]controller/login[/b]') instead of Code: $this->form_validation->run('[b]accounts/login[/b]') And it worked. Not sure about the logic of putting the word controller. What should I do if I had the two same name methods in two different classes ? Ex: Code: // file a.php Problems loading validation rules in config file - El Forum - 01-17-2010 [eluser]MurkeyDismal[/eluser] I may be wrong, but shouldn't line 5 read Code: parent::Controller(); Problems loading validation rules in config file - El Forum - 01-17-2010 [eluser]ekevin[/eluser] @MurkeyDismal: you're not wrong ![]() Problems loading validation rules in config file - El Forum - 01-17-2010 [eluser]built2fall[/eluser] [quote author="MurkeyDismal" date="1263769665"]I may be wrong, but shouldn't line 5 read Code: parent::Controller(); parent::__construct() and parent::Controller() are equivalent as far as I know--they both call the constructor of the parent class. If I'm not mistaken, the latter is simply used for backward compatibility with PHP4. http://us2.php.net/construct |