CI 2.0 - extended form_validation does not load config file |
[eluser]solidrockit[/eluser]
Hello I know this is an already commented issue but I am not able to get it working although I have read the doc and many post in the forum: 1) We have a extended form_validation class and the added valid_date method works great Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 2) We have the config file in .\application\config\form_validation.php something like this Code: $config = array( 3) In the controller we have the Code: $this->load->library('form_validation'); Code: if ($this->form_validation->run('validate')==FALSE){ 4) I have already try to autoload the config file but no way. 5) If I leave the rules inside the controler(I mean not using the config file), the Code: if ($this->form_validation->run()==FALSE){ Am I missing something or is there something tricky? Many thanks
[eluser]kirkaracha[/eluser]
This might help: Form_validation class fails to locate rule-sets for certain URIs
[eluser]wiredesignz[/eluser]
@solidrockit, Your constructor overload is stopping the CI_Form_validation constructor from processing the config array().
[eluser]Chimpski[/eluser]
In the controller use: $this->form_validation->set_rules($this->config->item('name_of_form_validation_rule', 'form_validation')); if ($this->form_validation->run() == true) { //do stuff }
[eluser]solidrockit[/eluser]
Many thanks for your replies. This is what works for me in ..\application\libraries\MY_Form_validation.php: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Now the $config file is being loaded.
[eluser]Chimpski[/eluser]
I would prefer that method to directly calling it in with the: $this->form_validation->set_rules($this->config->item(‘name_of_form_validation_rule’, ‘form_validation’)); Did you have to do anything to make the MY_Form_validation.php get called? Added the file with your code and received an error: Call to undefined method CI_Form_validation::CI_Form_validation() I can't seem to find anything about this error.
[eluser]Chimpski[/eluser]
Oops that was a different MY. This is the errors I get with you MY_Form_validation: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); A PHP Error was encountered Severity: Warning Message: Missing argument 1 for MY_Form_validation::__construct(), called in C:\xampp\htdocs\ci2\system\core\Loader.php on line 949 and defined Filename: libraries/MY_Form_validation.php Line Number: 5 A PHP Error was encountered Severity: Notice Message: Undefined variable: config Filename: libraries/MY_Form_validation.php Line Number: 7 Not quite sure. I must be missing something. (Just learning CodeIgniter)
[eluser]steelaz[/eluser]
This is PHP related error (warning), not CI. Try this: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
[eluser]Chimpski[/eluser]
I fixed the issue with your code by removing the set rules call altogether and removing the $config from the ->run($config). Thanks for your help. |
Welcome Guest, Not a member yet? Register Sign In |