Acción edit y vista

 public function edit($id = null) {
 //Parte donde se recuperan los datos enviados por la vista y se guardan en la BD
 if ($this->request->is(array('post', 'put'))) {
 if ($this->Post->save($this->request->data)) {
 $this->Flash->success(__('Post actualizado.'));
 return $this->redirect(array('action' => 'index'));
 }
 $this->Flash->error(__('Unable to update your post.'));
 } else {
 //Parte donde se recupera el Post y se manda a la vista
 if (!$id) {
 throw new NotFoundException(__('Invalid post'));
 }

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

 if (!$this->request->data) {
 $this->request->data = $post;
 }
 }
 }
 <h1>Edit Post</h1>
<?php
echo $this->Form->create('Post');
echo $this->Form->input('title');
echo $this->Form->input('body', array('rows' => '3'));
echo $this->Form->input('id', array('type' => 'hidden'));
echo $this->Form->end('Save Post');
?>

Publicado por

Avatar del usuario

Juan Pablo Fuentes

Formador de programación y bases de datos