I am writing an editing function to update news information, my code is:
this is the function of the controller file:
public function editnews($id) { $this->layout = "news"; //tynemc call by this statement $this->loadModel('News'); //model call $this->loadModel('Category'); //load news category if ($this->request->is('post')) { if (move_uploaded_file($this->request->data['News']['image_url']['tmp_name'], WWW_ROOT . 'media/'. $this->request->data['News']['image_url']['name'])) { $this->request->data['News']['image_url'] = time() . $this->request->data['News']['image_url']['name']; }$this->News->save($this->request->data['News']);//data save by this statement $msg = '<div class="alert alert-success"> <button type="button" class="close" data-dismiss="alert">×</button> <strong> News update successfully </strong> </div>'; $this->Session-> setFlash($msg); return $this->redirect('editnews'); } if (!$this->request->data) { // id wise data search $data = $this->News->findById($id); $this->request->data = $data; } $this->set('categories', $this->Category->find("list"));//categories load in dropdown }
This is the ctp file form action code:
<?php echo $this->Form->create('News', array( 'inputDefaults' => array( 'label' => false, 'div' => false ), 'id' => 'form-validate', 'class' => 'form-horizontal', 'novalidate' => 'novalidate', 'enctype' => 'multipart/form-data', 'controller' => 'admins', 'action' => 'editnews' ) ); ?>
I did not edit the name, image, news, I canβt save the news information, why does it work like this and how can I fix my function to edit the record?
user4101645
source share