Exemplo n.º 1
0
 /**
  * Update function.
  * Updates an existing resource.
  *
  * @return void
  */
 protected function update()
 {
     // Check for token
     JSession::checkToken() or K2Response::throwError(JText::_('JINVALID_TOKEN'));
     // Ensure we have an id
     $id = $this->input->get('id', 0, 'int');
     if (!$id) {
         K2Response::throwError(JText::_('K2_INVALID_INPUT'));
     }
     // Get input data
     $data = $this->getInputData();
     // Pass data to the model
     $this->model->setState('data', $data);
     // Save
     $result = $this->model->save();
     // Handle save result
     if ($result) {
         // Save was successful try to checkin the row
         if (!$this->model->checkin($this->model->getState('id'))) {
             // An error occured while trying to checkin. Notify the client.
             K2Response::throwError($this->model->getError());
         }
         K2Response::setStatus(true);
     } else {
         // An error occured while saving. Notify the client.
         K2Response::throwError($this->model->getError());
     }
 }