Welcome Guest, Not a member yet? Register   Sign In
callback from model
#1

[eluser]smith[/eluser]
For those interested in keeping validation inside model. As you all know you can't use callback method from model, or you can but callback function has to be inside controller. I have tried something else, so you can use my method if you want:

make new validation.php that extends CI validation and put it in application/libraries:

MY_Validation.php
Code:
class MY_Validation extends CI_Validation {

    function MY_Validation()
    {
        parent::CI_Validation();
    }
    
    
    function additional_check($array)
    {
        // do something with your data, set error message, return false or true
    $this->set_message('additional_check', 'error');
    return false;
    }
}

in your controller construct load library and forms model:
controller:
Code:
$this->load->library('validation');
$this->load->model('forms');

in your model use callback as you would from controller, but without "callback_" prefix:

model:
Code:
$rules['some_field']   = "required|additional_check";

callback will work without any problem, and you get to keep validation inside model, forms in one model, callbacks in one library. I like it that way, it keeps my controllers pretty clean, so if anyone wants to use this too, be my guest Smile


Messages In This Thread
callback from model - by El Forum - 10-11-2007, 07:16 AM
callback from model - by El Forum - 10-11-2007, 12:18 PM
callback from model - by El Forum - 10-11-2007, 03:30 PM
callback from model - by El Forum - 10-11-2007, 03:48 PM
callback from model - by El Forum - 10-11-2007, 03:56 PM
callback from model - by El Forum - 10-11-2007, 04:04 PM
callback from model - by El Forum - 10-11-2007, 04:11 PM
callback from model - by El Forum - 10-11-2007, 04:11 PM
callback from model - by El Forum - 10-11-2007, 04:23 PM
callback from model - by El Forum - 10-11-2007, 04:57 PM
callback from model - by El Forum - 10-11-2007, 05:18 PM
callback from model - by El Forum - 10-11-2007, 05:51 PM
callback from model - by El Forum - 10-11-2007, 08:38 PM



Theme © iAndrew 2016 - Forum software by © MyBB