Welcome Guest, Not a member yet? Register   Sign In
best way to add validation functions
#1

[eluser]skattabrain[/eluser]
hello,

i've been trying to get my validation callbacks into some sort of single file so i can reuse the fucntions within this project as well as others.

i've been adding these validation functions to a helper file, but things don't seem to work right. is there a better way than to add these fucntions in a helper?

should i extend the validation class instead?

i haven't extended ci in anyway yet ... trying to get the most out of a vanilla install for easy upgrading etc ...
#2

[eluser]ontguy[/eluser]
I think extending the validation class is the best way to centralize callbacks:

So I could have a username_duplicate_check callback function included in MY_Validation.php, then use it in the validation rules:
Code:
$rules['username'] = 'trim|required|username_duplicate_check';

I have been giving some thought about where to centralize rules for fields used in multiple controllers; I think a config file maybe the place to do it or maybe even putting it MY_Validation and overriding it if needed.




Theme © iAndrew 2016 - Forum software by © MyBB