Cakephp Edit function is not working if($this->Category->save($this->request->data)) -



Cakephp Edit function is not working if($this->Category->save($this->request->data)) -

i have 2 columns in database, id , name under table categories. edit function:

public function edit($id = null){ if($this->category->exists($id)){ throw new notfoundexception (__('id not found ')); } if($this->auth->user('role')=='admin'){ if(!$id){ throw new notfoundexception(__('id not set')); } $data=$this->category->findbyid($id); if(!$data){ throw new notfoundexception(__('id not found in database')); } if($this->request->is(array('post','put')) ){ if($this->category->save($this->request->data)){ $this->session->setflash('the info has been edited successfully'); homecoming $this->redirect(array('action' => 'index')); //$this->redirect('index'); } else{ $this->session->setflash("the info not edited"); $this->redirect(array('controller'=>'categories','action'=>'index')); } } // else{ // $options = array('conditions' => array('category.' . $this->category->primarykey => $id)); // $this->request->data = $this->category->find('first', $options); // } $this->request->data=$data; } else{ $this->session->setflash(__('you not have right this')); $this->redirect('index'); } }

my categories/edit.ctp

<?php echo $this->form->create('category'); ?> <fieldset> <legend><?php echo __('edit category'); ?></legend> <?php echo $this->form->input('id'); echo $this->form->input('name'); echo $this->form->input('id',array('type'=>'hidden')); ?> </fieldset> <?php echo $this->form->end(__('submit')); ?>

whenever seek edit , update form, $this->session->setflash("the info not edited"); gets executed.

try: $this->category->id = $this->request->data['id']; if($this->category->save($this->request->data)){ $this->session->setflash('the info has been edited successfully'); homecoming $this->redirect(array('action' => 'index')); //$this->redirect('index'); }

cakephp

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -