アクティブなレコードを使用してパスワード変更コードを作成しようとしています。それは問題なく動作しますが、パスワードが正常に変更されたかどうか、または現在のパスワードが実際に間違っていたかどうかを知る必要があります。
影響を受けた行を使用して、影響を受けたレコードの数を確認しています。値は 1 または 0 である必要があります。パスワードが正常に変更された場合は 1、変更されていない場合は 0 (つまり、入力された現在のパスワードが間違っていた) です。ユーザー名が一意であるため、影響を受ける行が 1 を超えることはありません。したがって、私がアプローチしている方法で機能するはずです。ただし、影響を受ける行関数は常に 1 を返すため、機能していないようです。
コード コントローラーは次のとおりです。
function changepass() {
$this->form_validation->set_rules('pass', 'Password', 'required|matches[passconf]|min_length[6]|max_length[12]');
$this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
if ($this->form_validation->run() == false) {
//if not valid
$this->session->set_flashdata('message', validation_errors());
redirect('profile');
} else {
//if valid
$current = $this->input->post('current');
$change = $this->input->post('pass');
$id = $this->input->post('id');
$flag = $this->profile_model->update_pass($current, $change, $id);
if ($flag = true) {// If Successful
$this->session->set_flashdata('message', $flag);
} else { // If Unsuccessful
$this->session->set_flashdata('message', 'Current Password is not valid');
}
redirect('profile');
}
}
モデル:
function update_pass($current,$change,$id) {
$data = array('pass'=>$change);
$this->db->where('id',$id);
$this->db->where('pass',$current);
$this->db->update('users',$data);
return ($this->db->affected_rows());
}