Description
I needed a simple way of storing Validation rules callbacks into Models. This had to be made with minimal modifications to the Form validation library and resembling as much as possible the CI conventions for validation rules.
Once installed the library you will only need to append _model[your_model_name] to your validation rule callback name, where your_model_name indicates the model which contains the callback function.
If no model is specified, it is assumed that the callback resides in the Controller code (as CI behaves by default).
Example
Let’s say you want to assign the _validate_authcode callback to the authcode form field:
callback__validate_authcode
‘_validate_authcode’ callback is located in the requested Controller (the default CI’s callback behavior)
$this->form_validation->set_rules('authcode', 'Authorization Code', 'callback__validate_authcode');
callback__validate_authcode_model[admin]
‘_validate_authcode’ callback is located in the ‘admin’ Model
$this->form_validation->set_rules('authcode', 'Authorization Code', 'callback__validate_authcode_model[admin]');
callback__validate_authcode_model[public]
‘_validate_authcode’ callback is located in the ‘public’ Model
$this->form_validation->set_rules('authcode', 'Authorization Code', 'callback__validate_authcode_model[public]');
