alzen8work / CodeIgniter-HMVC

CodeIgniter 3.1.10 with HMVC
MIT License
45 stars 55 forks source link

I can use the custom validtion in any modules. #2

Closed satanand7 closed 5 years ago

satanand7 commented 6 years ago

I have make a custom validation for date formate check but when I use in in validation rule as callback function it show the error that the function is not define. May be it will called with module. Please help me to find the solution.

jinbatsu commented 6 years ago

When using form validation with MX you will need to extend the CI_Form_validation class as shown below,

/** application/libraries/MY_Form_validation **/ 
class MY_Form_validation extends CI_Form_validation 
{
    public $CI;
}

before assigning the current controller as the $CI variable to the form_validation library. This will allow your callback methods to function properly.

class Xyz extends MX_Controller 
{
    function __construct()
    {
        parent::__construct();

        $this->load->library('form_validation');
        $this->form_validation->CI =& $this;
    }
}

This will remove HMVC related callback problem without any changes to your code. source: https://stackoverflow.com/a/38357164

alzen8work commented 5 years ago

I have make a custom validation for date formate check but when I use in in validation rule as callback function it show the error that the function is not define. May be it will called with module. Please help me to find the solution.

thanks raising the issue, i have already make some changes which would fix this issue.

alzen8work commented 5 years ago

This will remove HMVC related callback problem without any changes to your code.

thanks for the advice, already fix some of it accordingly