Validation callbacks in libraries. - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Validation callbacks in libraries. (/showthread.php?tid=5728) |
Validation callbacks in libraries. - El Forum - 02-01-2008 [eluser]Chris Newton[/eluser] I have a registration library which works great, except for custom callbacks. They just get totally ignored. $rules['username'] = 'callback_username_check'; This callback, when added to a library is completely ignored, unless that function exists in the calling controller. Is there some sort of method to use callbacks within a library? Maybe using a helper in addition to the library? I'm going to try that... Validation callbacks in libraries. - El Forum - 02-01-2008 [eluser]Chris Newton[/eluser] Nope. that doesn't work. Well, at least I can't figure out how anyway. Validation callbacks in libraries. - El Forum - 02-02-2008 [eluser]Nanodeath[/eluser] In libraries/Validation.php, I found this relevant bit of code: Code: if ($callback === TRUE) Now, make of that how you will...I don't have the solution, but one hack you could try would be to not prefix your define with callback_, and then define it as a function just below your library instead of a method in your library. Obviously not a great solution, but I'm not sure if there really is one, unless you want to modify the Validation library to iterate through every loaded library to try to find a corresponding method. Validation callbacks in libraries. - El Forum - 02-02-2008 [eluser]Chris Newton[/eluser] I ended up using regular validation operations. THEN I added private functions at the bottom of my library. These private functions are called at the end of the validation testing like so: Code: $this->_username_check($CI->validation->username); If those private functions fail, they do something like this: Code: $CI->validation->username_error='<span class="error">That username is taken</span>'; Validation callbacks in libraries. - El Forum - 02-02-2008 [eluser]wiredesignz[/eluser] I posted a week ago, this change to the validation library allows callbacks into models or libraries. http://ellislab.com/forums/viewthread/69797/ Validation callbacks in libraries. - El Forum - 02-02-2008 [eluser]tomcode[/eluser] I extend the Validation Class with my callbacks. Code: class MY_Validation extends CI_Validation{ |