For editing user information in cake php by clicking on edit button we have to first pass user id in URL by using below code in our view.
<?php echo $this->Html->link('Edit',array('action'=>'edit/'.$user['User']['id']));
And we have to put the following code in that function where we will wright code for editing data in our controller.
public function edit($id = null){
$user = $this->User->findById($id); //getting user information on the bases of id which we are passing
if ($this->request->is('post')) {
if ($this->User->save($this->request->data)) {
$this->Session->setFlash(__('The user has been updated'));
$this->redirect(array('action' => 'display', $id));
}
else{
$this->Session->setFlash(__('Unable to update your user.'));
}
}
if (!$this->request->data) {
$this->request->data = $user;
}
}
0 Comment(s)