cakephp edit posts doesnt do what it should do -


i want edit posts, when acess http://... /posts/edit/2 shows flash message post has been updated, whats wrong ? doesnt show edit form...

function edit($id = null) {     $this->post->id = $id;     if($this->request->is('post')){         $this->request->data = $this->post->read();      }else {         if($this->post->save($this->request->data)){             $this->session->setflash('the post has been updated');             $this->redirect(array('action'=>'index'));         }     } } 

my edit page

<h2>edit post</h2> <?php echo $this->form->create('post',array('action'=>'edit')); echo $this->form->input('title'); echo $this->form->input('body'); echo $this->form->input('id', array('type'=>'hidden')); echo $this->form->end('edit post'); ?> 

your if() condition wrong :

  1. if post data, read data , put in $this->request->data edit form
  2. else : save empty $this->request->data , redirect flash message.

so when access form, not post data, save, redirect. fix modify condition in if() read when not post , save when post :

if(!$this->request->is('post')) 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -