Welcome Guest, Not a member yet? Register   Sign In
Where to put form callback functions?
#9

[eluser]Evil Wizard[/eluser]
How does the newly created library know that the validation callback is for it? I know it's possible to have callback functions outside of the current object scope but then the call to the function and the object it resides in is explicitly specified, i.e.
Code:
class My_callback {
    public static function array_index($foo)
    {
        return implode('', $foo);
    }
}
$bar = array_map(array('My_callback', 'array_index'), array(1,2,3,4,'test', 'foo' => 'bar'));
but I don't know how you would tell the validation library to use an alternative object than the controller, unless the validation rules are being set in the library then at that point then library object becomes the one responsible for the call back. I think the object that sets the validation rules will be the object that can house the rule callback function.
Code:
class My_callbacklibrary {
    public function set_rules()
    {
        $CI = get_instance() // object are passed by reference, no need for the =&
        $CI->form_validation->set_rules(array('field'=>'test','label'=>'My Test','rules'=>'trim|callback_username_check'));
    }
    // the scope of the method does not matter as the self object will be calling the callback
    // so the method will always be in scope
    protected function username_check($username)
    {
        echo $username;
    }
}
Hope that helps a little


Messages In This Thread
Where to put form callback functions? - by El Forum - 06-15-2009, 08:53 AM
Where to put form callback functions? - by El Forum - 06-15-2009, 08:57 AM
Where to put form callback functions? - by El Forum - 06-15-2009, 09:04 AM
Where to put form callback functions? - by El Forum - 06-15-2009, 09:08 AM
Where to put form callback functions? - by El Forum - 06-15-2009, 09:38 AM
Where to put form callback functions? - by El Forum - 06-15-2009, 09:52 AM
Where to put form callback functions? - by El Forum - 06-15-2009, 09:53 AM
Where to put form callback functions? - by El Forum - 06-15-2009, 09:54 AM
Where to put form callback functions? - by El Forum - 06-15-2009, 10:04 AM
Where to put form callback functions? - by El Forum - 06-15-2009, 10:26 AM
Where to put form callback functions? - by El Forum - 06-15-2009, 10:54 AM



Theme © iAndrew 2016 - Forum software by © MyBB