Yup, IMO the model shouldn’t have to deal with validation, it should be virtually independent. However, the model does know best how its data should be validated and prepped. The model could always provide the validation rules to the controller. It would be nice though if callbacks could be within a library?
thanks for reply.
i need to run a database query to see if the user is choosing a unique username. so i need a callback which execute database query. how could i do it with a library?
You can do that between your controller and model. Simply create the callback function in your controller that checks the username by calling a function from your model. The model function should return either true or false. The controller callback function should also return true or false—but it should also set the error message for the validation class.