views:

55

answers:

1
<?php
class MY_Form_validation extends CI_Form_validation {

    function My_Form_validation()
    {
        parent::CI_Form_validation();
    }

}  

This is the code in the file MY_Form_validation.php that I have created in my CI libraries folder. There were some functions in there but i removed them to try and get to the bottom of this.

Utilizing this library extension, form validation simply does not work at all. I have all my form validation rules in a config file.

If i delete MY_Form_validation.php everything works perfectly.

A post on the CodeIgniter board yielded no results.

Perhaps someone here could help? Thanks

+1  A: 

Try this instead. You need to pass the $config array from the extended class to the CI_Form_validation. Also make sure the spelling is correct and case sensitive.

class MY_Form_validation extends CI_Form_validation {

    function MY_Form_validation( $config = array() )
    {
        parent::CI_Form_validation($config);
    }
rkj
Brilliant - Using that, the normal validation rules work. I have not had a chance to implement my custom functions yet, but I imagine they will work. Could you elaborate on as to why this $config var needs to be passed? Is this documented anywhere? On the CodeIgniter forums I was informed by an established member that they used the same code as MINE and it worked. So I have a resolution, but dont really understand it.. Cheers
Thomas Clowes
The CI loader class of checks for a corresponding config file when it is loading libraries. This happens _ci_init_class() in CI_Loader. The $config array defined in system/application/config/form_validation.php is passed to the extended class, NOT to CI_Form_validation. So this is why you will have to pass it from your extended class yourself to CI_Form_validation in the constructor - you can set new rules here too. Hope this helps you a bit :)
rkj