top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to Update a particular record's data in CakePHP Framework?

0 votes
333 views
How to Update a particular record's data in CakePHP Framework?
posted Jul 22, 2014 by Amritpal Singh

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Suppose you are using UsersController and trying to update the record of Model -User via action of edit using id parameter. Then Your code goes Here:

<?php
class UsersController extends AppController
public function edit($id = null) {
if (!$id) {
throw new NotFoundException(__('Invalid post'));
}

$user= $this->Post->findById($id);
if (!$user) {
    throw new NotFoundException(__('Invalid post'));
}

if ($this->request->is(array('post', 'put'))) {
    $this->User->id = $id;
    if ($this->User->save($this->request->data)) {
        $this->Session->setFlash(__('Your User's record has been updated.'));
        return $this->redirect(array('action' => 'index'));
    }
    $this->Session->setFlash(__('Unable to update your User.'));
}

if (!$this->request->data) {
    $this->request->data = $post;
}

}
}

?>>

answer Jul 23, 2014 by Rahul Mahajan
...