I want to use a confirmation popup to delete my items, so this is my delete action :
public function deleteAction()
{
$id = (int) $this->params()->fromRoute('id', 0);
$article = $this->getObjectManager()->find('\Application\Entity\Article', $id);
if ($this->zfcUserAuthentication()->hasIdentity()) {
if ($this->request->isPost())
{
$this->getObjectManager()->remove($article);
$this->getObjectManager()->flush();
return $this->redirect()->toRoute('blog');
}
}
else
{
return $this->redirect()->toRoute('user');
}
return new ViewModel(array('article' => $article));
}
and this is my blog view where i have the delete link :
<a href="<?php echo $this->url('delete', array('action'=>'delete', 'id' => $articles->getId())) ?>" class="btn btn-default btn-lg" onclick="if (confirm('Are you sure?')) { document.location = this.href; } return false;" id="dialog">Delete Article</a>
<?php endif;?>
<script type="text/javascript">
$(function() {
$( "#dialog:ui-dialog" ).dialog( "destroy" );
$( "#dialog-confirm" ).dialog({
resizable: false,
height:140,
modal: true,
buttons: {
"Are you sure": function() {
document.form.submit();
$( this ).dialog( "close" );
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
});
</script>
the problem is when i press the link it's redirected to the delete.phtml view, what i want is to delete the item when i confirm the popup.
So please if someone has any solution i will be very appreciative :)