TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
no errors after callback function
  • 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

    $users_blog = ORM::factory('UsersBlog');
    $users_blog->values($_POST);

    if ($users_blog->check()) {
    $users_blog->save();
    } else {
    $errors = $users_blog->validate()->errors('addblog');
    var_dump($errors);
    exit;
    }

    As result i have no errors after sending POST data but why ?
  • 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.
  • From [the docs](http://kohanaframework.org/guide/security.validation):

    > 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.
  • okay, so callback which is declared in $_callbacks differ from callback declared in rule

    $post->rule('username', 'User_Model::unique_username');
    ?
  • >okay, so callback which is declared in $_callbacks differ from callback declared in rule

    Yes, rules always return a boolean, "callbacks" (as in validate callbacks) must set an error message (if you want them to fail).
  • 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.