php - Why does CakePHP add New Rows when 'post' is replaced by 'get'? -
i edit row on post table or add new row edit() function in postscontroller. function looks this:
public function edit($id = null) { // has form data been posted? if ($this->request->is('post')) { //replaced 'post' 'get' in line // if form data can validated , saved... if ($this->post->save($this->request->data)) { // set session flash message , redirect. $this->session->setflash('updated post!'); return $this->redirect('/posts'); } } // if no form data, find post edited // , hand view. $this->set('post', $this->post->findbyid($id));
}
i replaced 'post' 'get' see happen , went on creating new rows without taking me form. still flash message 'updated post!'
, without taking form data.
if code in edit.ctp required, here is:
<?php echo $this->form->create('post'); echo $this->form->input('id', array('type' => 'hidden','default'=>$post['post' ['id'])); echo $this->form->input('title',array('default'=>$post['post']['title'])); echo $this->form->input('body',array('default'=>$post['post']['body'])); echo $this->form->end('update'); ?>
any thoughts on why might happening?
edit: added cakephp version
i using cakephp 2.4.5
what doing makes no sense. why want switch "post" "get" here? of course generate new rows, trigger save on each page load (get). don't that. code had there fine - if took put consideration. edit forms, not post, but:
if ($this->request->is('put')) {}
ps: if want make sure works both add/edit, use
if ($this->request->is(array('post', 'put')) {}
but never replace "get".
Comments
Post a Comment