Here is a part of my model class Model_UsersProject extends ORM { protected $_table_name = 'users_projects'; protected $_primary_key = 'id';
protected $_ignored_columns = array( 'blog_ids' //ignored column which comes from $_POST ); ... protected $_callbacks = array ( 'blog_ids' => array('not_empty_blog_ids') //define name of callback function );
public function not_empty_blog_ids(Validate $validate, $field_name) //callback function { return false; // =) yeah its just dummy return }
And a part of controller which validates data after sending POST data
Validate callbacks don't return a boolean like rules do. They need to manually add their own error messages. With your dummy example you want to replace the return false; with $validate->error($field_name, 'dummy_error'); You can see more information about validate callbacks in the wiki.
> A callback is custom method that can access the entire Validate object. The return value of a callback is ignored. Instead, the callback must manually add an error to the object using Validate::error on failure.
As I noticed, callbacks are not really meant for validations, but for extra processing. It just happens that it can also do validation. Callbacks can validate, filter, update things, etc.
You can... but I would say it's bad practice to use it for other stuff. Really validation should be about validating data, not about doing updates or making changes to the data.