[eluser]matt_a[/eluser]
I've seen plenty of tutorials out there on creating a User model, and they're all great. I've encountered an issue that I can't seem to find a solution for, though: when a user is attempting to create a new account.
I obviously want to check to make sure the same username isn't already in the database, but I also want to make sure the email address isn't either. In my User model, I've created a function called _user_exists(),
Code:
function _user_exists($attribute, $value)
{
$this->db->where($attribute, $value);
$result = $this->db->get('users');
return $result->num_rows() > 0;
}
and I call this function on the username and email provided in a create() function. My problem is generating the correct error message to display to the user (username is already in use or someone already registered with that email address). I don't know the best way to do this. I have a few ideas though..
1) create a variable, say $message, and set it appropriately. then load a view and pass it $message (is it ok to load a view from a model, though?)
Any suggestions?