before add user, check if this login (email etc...) already exists in database |
[eluser]Unknown[/eluser]
Hi there This is my first post here, but I think not last Now i am creating code to register new users at site. It puts some values like user_name, password, email in database. I wonder if CI has some functions/classes/helpers etc to check automaticly if in database i have already thesame user_name and/or email? Or i need to write code to check it myself
[eluser]JWarren[/eluser]
I don't know if CI has something built in, but it doesn't take much to add a function to a model to do it. quick example: Code: function email_registered($email) { Code: if ($this->model_name->email_registered($_POST['email']) > '0') {
[eluser]Unknown[/eluser]
Ok, thank you very much! btw> i see that it should be (first code) in Models, right? I still don't undertstand well MVC idea
[eluser]JWarren[/eluser]
I keep any functions that read from or write to a database in a model. Then load the model in a controller and call it's functions in the controller or view. It has done wonders to keep my code much more organized.
[eluser]internut[/eluser]
Form validation has a callback function you can use as well to do a SQL lookup to check if it exists. http://ellislab.com/codeigniter/user-gui...#callbacks |
Welcome Guest, Not a member yet? Register Sign In |