[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