I think what you are looking for is the Model->exists() method. Please see
a baked Cake 2.0 edit method.
/**
* edit method
*
* @param string $id
* @return void
*/
public function edit($id = null) {
$this->{YourModel}->id = $id;
if (!$this->{YourModel}->exists()) {
throw new NotFoundException(__('Invalid {YourModel} record'));
}
if ($this->request->is('post') || $this->request->is('put')) {
if ($this->{YourModel}->save($this->request->data)) {
$this->Session->setFlash(__('The {YourModel} record has been saved'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The {YourModel} record could not be saved.
Please, try again.'));
}
} else {
$this->request->data = $this->{YourModel}->read(null, $id);
}
}
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php