0

I am developing an application using codeigniter HMVC architecture. I am pretty new to HMVC and have just started to explore it. Recently I began to transform my code into HMVC from MVC in codeigniter. I have developed a custom authentication library which resides in my application/libraries folder which has authentication rules for registration and login form. I have written some callback functions in my validations which suddenly stopped working when I opted for HMVC framework. I came across some references to fix this but all in vain. I couldn't somehow make my code working. According to a common suggestion I have built up a MY_Form_validation as below:

class MY_Form_validation extends CI_Form_validation
{
    public $CI;
}

And then in my authentication library I am using this:

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

and for validation I use this:

if($this->CI->form_validation->run($this->CI)==FALSE)

But somehow my validation check is not being performed. It used to work on my MVC framework.

SanksR
  • 5
  • 2

1 Answers1

0

"$this->CI->form_validation->CI = $this->CI;" Why doing lot of cross references?

This is how I have my extended Form Validation library and it is working.

class MY_Form_validation extends CI_Form_validation {
    public function valid_url($url) {
        $pattern = '/^http(s)?:\/\/[a-z0-9]{1}[0-9a-zA-Z\-]*([\.a-zA-Z])+([a-zA-Z0-9\-\/\?=])*$/';
        if (preg_match($pattern, $url)) {
            return true;
        } else {
            $this->set_message('valid_url', "%s is not a valid url.");
            return false;
        }
    }
}

Then you can use like you use the form validation library.

Nish
  • 2,296
  • 2
  • 14
  • 19