im trying to delete a record with following code:
in Controller:
public function delete($id = null) {
if (!$this->Modelname->exists($id)) {
throw new NotFoundException(__('Modelname ungültig'));
}
$this->Modelname->id = $id;
$this->request->onlyAllow('post', 'delete');
if ($this->Modelname->delete()) {
$this->Session->setFlash(__('Modelname wurde gelöscht.'));
return $this->redirect(array('controller' => 'modelnames', 'action' => 'index'));
}
$this->Session->setFlash(__('Modelname wurde nicht gelöscht.'));
}
in View:
<?= $this->Form->postLink(__('Delete'), array('controller' => 'modelnames', 'action' => 'delete', $id), array('confirm' => 'Soll dieser Eintrag wirklich gelöscht werden?')) ?>
Usually this works for me, but now its just refreshing the page without doing anything.. mhh any ideas?
postLinkis working well as it is generating equivalent html for post method.Well if you need to allow only particular request (post,delete) there you can do following either: