Validation callbacks in libraries. |
[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...
[eluser]Chris Newton[/eluser]
Nope. that doesn't work. Well, at least I can't figure out how anyway.
[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.
[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>';
[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/
[eluser]tomcode[/eluser]
I extend the Validation Class with my callbacks. Code: class MY_Validation extends CI_Validation{ |
Welcome Guest, Not a member yet? Register Sign In |