EllisLab text mark
Advanced Search
     
validation with callbacks
Posted: 22 July 2007 05:34 AM   [ Ignore ]
Avatar
Joined: 2007-04-08
8 posts

i want to put my callback in model
is it possible?

 
Posted: 22 July 2007 07:50 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2007-02-26
619 posts

Sorry but my intent is not to answer your question—rather to ask why you would do that?

 Signature 

Developer13.com
Here is my nicely documented CodeIgniter Base CRUD Model

 
Posted: 22 July 2007 08:02 PM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2007-02-06
743 posts

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?

 Signature 

“I am the terror that flaps in the night”

 
Posted: 23 July 2007 12:45 AM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2007-04-08
8 posts

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?

 
Posted: 23 July 2007 01:24 AM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2007-02-26
619 posts

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.

 Signature 

Developer13.com
Here is my nicely documented CodeIgniter Base CRUD Model