Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Users_Controller
- public function ajax_update()
- {
- if ($input = $this->input->post()) {
- $user = new User_Model(Session::get('user_id', FALSE));
- $profile = new Profile_Model(Session::get('user_id', FALSE));
- // would the best way to be use $input_user and $input_validate then merge error arrays?
- if ($user->validate($input, 'update') && $profile->validate($input)) {
- if ( ! empty($input['password']))
- $user->hashed_password = Auth::hash_password($input['password']);
- $user->save();
- $profile->save();
- $json = array('success' => TRUE);
- $this->template->body = json_encode($json);
- } else {
- foreach ($input->errors('form_errors') as $error) {
- $errors[] = $error;
- }
- $json = array('success' => FALSE, 'errors' => $errors);
- $this->template->body = json_encode($json);
- }
- }
- }
- ////////////////////////
- //////////////////////
- ///// User_Model extends ORM
- public function validate(array & $input, $action)
- {
- $input = new Validation($input);
- if ($action == 'update')
- $input->pre_filter('trim')
- ->add_rules('name', 'required')
- ->add_rules('email', 'required', 'valid::email')
- ->add_rules('email', array($this, '_unique_email'))
- ->add_rules('password', 'length[4,20]')
- ->add_rules('password', 'matches[confirm_password]');
- return parent::validate($input);
- }
Add Comment
Please, Sign In to add comment