public function update_user($id)
{
if($this->request->getMethod() == 'get'){
if (session()->get('login') != "") {
$userModel = new UserModel();
$user = $userModel->find($id);
$profilModel = new ProfilModel();
$profilsItems = $profilModel->findAll();
$data = [
'title_meta' => view('partials/title-meta', ['title' => 'Utilisateurs']),
'page_title' => view('partials/page-title', ['title' => 'UpdateUser', 'pagetitle' => 'GestionUtilisateurs', 'link' => 'users']),
'user' => $user,
'profils' => $profilsItems
];
return view('admin/edit_user_2', $data);
} else {
return redirect()->to('/login');
}
}
if($this->request->getMethod() == 'post'){
// ---- store details in database
$model = new UserModel();
$updateData = [
'nom' => $this->request->getVar('nom'),
'prenom' => $this->request->getVar('prenom'),
'email' => $this->request->getVar('email'),
'mobile' => $this->request->getVar('mobile'),
'tel' => $this->request->getVar('tel'),
'id_profil' => $this->request->getVar('id_profil')
];
$model->where('id', $id)
->set($updateData)
->update();
return redirect()->to('/users');
}
}
Thanks for your help !