Welcome Guest, Not a member yet? Register   Sign In
loading a model from within a custom library or helper file

Personally I dont really have much of a problem loading models in my libraries
But here is something else to consider.
If you use a callback in the standard validation library you can still check for unique usernames or email addresses

You need to create the callback function in the controller, or extend the validation class and put it there.
Then your callback function could call your model and get it to do the validation

sample code in method of controller
// get validation rules from model
function unique_username($username) {
  return $this->user->unique_username($username);
} // unique_username()

function unique_email($email) {
  return $this->user->unique_email($email);
} // unique_email()

Now in your model
function validationRules() {
  return array(
} // validationRules()

function unique_username($str) {
  // code to determine if the username is unique
  return (bool) $result;
} // unique_username()

function unique_email($str) {
  // code to determine if the email is unique
  return (bool) $result;
} // unique_email()

Now what I havent included in the code is that to properly determine if the username and email are unique you will need to know the id of the current user so that your queries are able to filter out the current record.
To do this simply set a property of the user model that is the id before the validation->run

Anyway this is a start...

Messages In This Thread
loading a model from within a custom library or helper file - by El Forum - 12-15-2007, 05:24 PM

Theme © iAndrew 2016 - Forum software by © MyBB