如何在确认弹出窗口中使用zend delete动作?

我想使用确认弹出窗口删除我的项目,所以这是我的删除操作:

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)); } 

这是我的博客视图,我有删除链接:

 <a href="https://stackoverflow.com/questions/21991035/how-to-use-zend-delete-action-in-confirmation-popup/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   $(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" ); } } }); });  

问题是,当我按下链接时,它被重定向到delete.phtml视图,我想要的是在我确认弹出窗口时删除该项目。

所以,如果有人有任何解决方案,我将非常感激:)

你可以使用confirm方法。

 if (window.confirm('Are you sure you want to delete?')) { window.location = "https://stackoverflow.com/questions/21991035/how-to-use-zend-delete-action-in-confirmation-popup/url('delete', array('action'=>'delete', 'id' => $articles->getId())) ?>" } else { // do nothing } 

如果要使用jQuery UI对话框,

  buttons: { "Are you sure": function() { window.location = "https://stackoverflow.com/questions/21991035/how-to-use-zend-delete-action-in-confirmation-popup/url('delete', array('action'=>'delete', 'id' => $articles->getId())) ?>" $( this ).dialog( "close" ); }, Cancel: function() { $( this ).dialog( "close" ); } } 

我知道这是一个老问题,但它对我有帮助。 所以我认为必须有其他人也在寻找答案。 所以我在这里怎么做..

  1. 转到http://adriancallaghan.co.uk/jquery-confirmation-box-thickbox/

  2. 下载并将javascript保存到’js’文件夹中(我放入’js / azza / deletebox.js’)

  3. 然后在视图* .phtml文件中添加指向该文件的链接

     $this->inlineScript()->prependFile($this->basePath('js/azza/deletebox.js')); 
  4. 然后按如下方式编辑你的href

     getNama(); ?>" id="dialog-confirm" class="dialog-confirm">Delete 
  5. 将’id’和’class’设置为“dialog-confirm”以触发javascript函数非常重要

  6. 并且您还需要Jquery和Jquery-UI才能使用此脚本

而已…