index.ctp
<?php foreach($posts as $post) : ?> <!-- <li><?= $this->Html->link($post->title, ['controller'=>'Post', 'action'=>'view',$post->id]); ?></li> --> <li><?= $this->Html->link($post->title, ['action'=>'view',$post->id]); ?> <?= $this->Html->link('[Edit]', ['action'=>'edit',$post->id],['class'=>'fs12']); ?> <?= $this->Form->postLink( '[x]', ['action'=>'delete', $post->id], ['confirm'=>'Are you sure?', 'class'=>'fs12'] ); ?> </li> <?php endforeach; ?>
PostsController.ctp
public function delete($id = null) { $this->request->allowMethod(['post', 'delete']); $post = $this->Posts->get($id); if($this->Posts->delete($post)){ $this->Flash->success('Delete Success!'); } else { $this->Flash->error('Delete Error!'); } return $this->redirect(['action'=>'index']); }