You can pass an additional validation object to save, create, and update. So your example would look like this:
public static function get_password_validation($values) { return Validation::factory($values) ->label('password', 'password') ->label('password_confirm', 'repeat password') ->rule('password', 'not_empty') ->rule('password', 'min_length', array(':value', 8)) ->rule('password_confirm', 'matches', array(':validation', ':field', 'password')); } public function create_user($values, $keys) { $external = Model_User::get_password_validation($values); $this->values($values, $keys); return $this->create($external); }
Note how password verification is passed to the create method.
The value of $keys indicates which values should be stored in the model. "password_confirm" was not in this list, so it is ignored. This feature is also related to security, you do not want users to manually set the identifier in their POST request.
You can then create the user by calling create_user :
$user->create_user($_POST, array('username', 'email', 'password'));
source share