I am using cakephp 2.
Can I use the postLink function for a helper form to update a post? Basically, I want the "Approve" button, which changes the "Approved" field of the entry to 1.
Does everything I can find relate only to the execution of the delete function? The documents also do not contain detailed information.
Any help would be great, thanks in advance
My code is:
<?php echo $this->Form->postLink(__('Approve'), array( 'controller' => 'expenseclaims', 'action' => 'edit', $expenseClaim['ExpenseClaim']['id'], 'approved' => '1', 'approved_by' => $adminUser, ), array( 'class' => 'btn btn-danger' ), __('Are you sure you want to Approve # %s?',$expenseClaim['ExpenseClaim']['id'] )); ?>
New code: see link for message:
<?php echo $this->Form->postLink(__('Approve'), array('action' => 'approve', $expenseClaim['ExpenseClaim']['id'], 'admin' => true), array('class' => 'btn btn-danger'), __('Are you sure you want to Approve # %s?',$expenseClaim['ExpenseClaim']['id'])); ?>
Controller Code:
public function admin_approve($id = null) { debug($this->request); $this->ExpenseClaim->id = $id; if (!$this->request->is('post') && !$this->request->is('put')) { throw new MethodNotAllowedException(); } if (!$this->ExpenseClaim->exists()) { throw new NotFoundException(__('Invalid expense claim')); } if ($this->request->is('post') || $this->request->is('put')) { $this->request->data['ExpenseClaim']['approved'] = '1'; $this->request->data['ExpenseClaim']['approved_by'] = $this->Auth->user('id'); if ($this->ExpenseClaim->save($this->request->data)) { $this->Session->setFlash('The expense claim has been Approved', 'flash_success'); $this->redirect(array('action' => 'index', 'admin' => true)); } else { $this->Session->setFlash('The expense claim could not be approved. Please, try again.', 'flash_failure'); } } }
source share