Welcome Guest, Not a member yet? Register   Sign In
callback problem in library
#1

[eluser]xavieremerson[/eluser]
hi...

I'm very new to CI. I'm extended CI_Form_validation to my_validation.. but after that i called that function in another my library by callback... But it is not working... Any one could help me... Please patience with me...


Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class control extends Controller  
{
    function control()
    {
        parent::Controller();
        $this->load->library("MY_User_manage");
    }

function register()
    {
        $this->my_user_manage->register();    
    }
....................



<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_User_manage  
{
    function MY_User_manage()
    {
        $this->CI = &get;_instance();
        $this->CI->load->library('form_validation');
        $this->CI->load->library('validation');
        $this->CI->load->library('my_validation');
        $this->CI->load->model('user_model');
    }

    function register()
    {
        $this->CI->form_validation->set_rules('username', 'Name', 'trim|required|max_length[15]|name_check');
        $this->CI->form_validation->set_rules('email','Email','trim|required|callback_email_check|valid_email|email_available');
        $this->CI->form_validation->set_rules('password','Password','trim|required|min_length[6]|max_length[12]|matches[confirm_password]');
        if ($this->CI->form_validation->run() == FALSE)
            {
.......

...
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Validation extends CI_Form_validation
{
    function MY_Form_Validation()
    {
        parent::CI_Form_Validation();
        // Get CI Instance
        $this->CI = &get;_instance();
    }
    function email_check($str)
    {
        if (!strcasecmp($str,'Email Id'))
        {
            $this->CI->validation->set_message('email_check', 'The %s field is required');
            return FALSE;
        }
        else
        {
            return TRUE;
        }
    }


Thankz in advance

please reply me to xavier
#2

[eluser]WanWizard[/eluser]
If the method is in the Form validation library (or your extension), you don't need the 'callback_' prefix. You only need that if the method is in your controller.
#3

[eluser]InsiteFX[/eluser]
Code:
// Should be:
$this->CI =& get_instance();
// Not this:
$this->CI = &get;_instance();

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB