![]() |
Validation callbacks into Models - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: Validation callbacks into Models (/showthread.php?tid=5514) Pages:
1
2
|
Validation callbacks into Models - El Forum - 01-24-2008 [eluser]wiredesignz[/eluser] I have created a Validation library modification which allows callbacks into Models. Save the existing Validation library as MY_validation with only the original run() function in it. Alter the class identifier to MY_ validation and extend it off CI_Validation. Change this code appropriatley: Code: // Call the function that corresponds to the rule my validation callback declaration then becomes: Code: $rules['username'] => ‘trim|required|callback_users_model->is_unique[username]’; Validation callbacks into Models - El Forum - 01-26-2008 [eluser]xwero[/eluser] It's great idea but i think it should be worked out some more. I think following format offers more flexibility. Code: $rules['username'] = 'trim|required|db_check[users,is_unique,password]' Code: function db_check($str,$param) edit : the model method Code: function is_unique($username,$arr) Validation callbacks into Models - El Forum - 01-28-2008 [eluser]xwero[/eluser] I've been thinking about this functionality the weekend and i think the possible combinations and the error checks are too much for a standard validation. The biggest problem with the current validation code is the very limited functionality of the rules, they only can output a boolean. Collecting the error string in the rules would help a lot. I'm busy hacking the validation class and this is something i will add. Validation callbacks into Models - El Forum - 01-28-2008 [eluser]wiredesignz[/eluser] :coolsmile: Validation callbacks into Models - El Forum - 02-02-2008 [eluser]dawnerd[/eluser] Oh please implement this. I'm tired of the way callbacks are setup. Also, how come the callback can't be prefixed with an underscore, say function _check_user rather than check_user. Validation callbacks into Models - El Forum - 02-02-2008 [eluser]Chris Newton[/eluser] I use callbacks with underscores all the time. You just have to call them like this; callback__myfunction Validation callbacks into Models - El Forum - 02-02-2008 [eluser]dawnerd[/eluser] Strange, I tried that and it failed. I'll give it another shot though. Validation callbacks into Models - El Forum - 02-02-2008 [eluser]Chris Newton[/eluser] The private callbacks can't be called if you're using the callbacks in libraries though. Libraries rely on the callback function to exist and be public in the calling controller. Validation callbacks into Models - El Forum - 04-22-2008 [eluser]beemr[/eluser] I've been able to use this in my library since wiredesignz gifted it to us. I added instructions to the wiki on how a library can call it. The instructions are for the latest revision which requires that the object gets passed into it own run() call. I'm also using the ActiveRecord_Class_Mod, so I added an example of an "is_unique" callback for use with that library. This validation enhancement makes a great complement for it. Validation callbacks into Models - El Forum - 04-23-2008 [eluser]beemr[/eluser] @mahuti Whoops. I didn't realize your post was off-topic. Anyhoo, it's still a great library to bring into ActiveRecord_Class_Mod. |