Kiedy edytuję użytkownika i zapisuję go, zapisuje on puste dane w bazie danych. Zapisuje wszystkie pozostałe pola w obecnej postaci, ale w przypadku hasła muszę ręcznie dodawać hasło za każdym razem, gdy edytuję użytkownika.Jak zatrzymać aktualizowanie hasła w codeigniter w metodzie edycji?
To jest moja metoda edit ::
if ($id)
{
$this->data['user'] = $this->user_m->get_emp($id);
count($this->data['user']) || $this->data['errors'][] = 'User could not be found';
$rules = $this->user_m->rules_admin;
$id || $rules['password']['rules'] .= '|required';
$this->form_validation->set_rules($rules);
// Process the form
if ($this->form_validation->run() == TRUE)
{
$data = $this->user_m->array_from_post(array('emp_id','name','last_name','email','password','phone','gender','designation','user_type','blood_group','date_birth','status','address'));
$data['password'] = $this->user_m->hash($data['password']);
$id = $this->session->userdata('id');
$this->user_m->save($data, $id);
redirect('admin/user/index');
}
}
// Load the view
$this->data['subview'] = 'employee/profile/edit';
$this->load->view('employee/_layout_main', $this->data);
To jest moja metoda HASH:
public function hash ($string)
{
return hash('sha512', $string . config_item('encryption_key'));
}
Teraz chcę, że kiedy edytować użytkownika i dont zmienić swoje hasło i nie chcesz hasło zaktualizowane do pustego, zamiast tego zachować ostatnią wstawioną passoword.
Ale mój kod generuje to zapytanie:
UPDATE `users` SET `emp_id` = '21', `name` = 'Rajan', `last_name` = 'Jadav', `email` = '[email protected]', `password` = '3eee66dbace42d2e671c52013e41de441b176dbaa0f7df33a5811b86c78b60ecb5328184bf1f5057f94817801140d7287f31c1fb06fa65550c356a33a8eec0db', `phone` = '999999999988', `gender` = 'Male', `designation` = 'Web', `user_type` = 'employee', `blood_group` = '+ve', `date_birth` = 'DD-MM-YYYY', `status` = 'Active', `address` = 'DD-MM-YYYY' WHERE `id` = 18
Kodeksu Model:
public function save($data, $id = NULL){
// Set timestamps
if ($this->_timestamps == TRUE) {
$now = date('Y-m-d H:i:s');
$id || $data['created'] = $now;
$data['modified'] = $now;
}
// Insert
if ($id === NULL) {
!isset($data[$this->_primary_key]) || $data[$this->_primary_key] = NULL;
$this->db->set($data);
$this->db->insert($this->_table_name);
$id = $this->db->insert_id();
}
// Update
else {
$filter = $this->_primary_filter;
$id = $filter($id);
$this->db->set($data);
$this->db->where($this->_primary_key, $id);
$this->db->update($this->_table_name);
}
return $id;
}
Jeśli usunąć metodę mieszania ze sterownika następnie wstawia puste pola i jeśli trzymać go wstawia fałszywy wartości
Pokaż również kod edycji użytkownika. –
@hardiksolanki to jest mój kod edycji tylko – Rajan
@hardiksolanki kiedy edytuję użytkownika wstawia puste hasło do bazy danych to mój problem – Rajan