如何在确认弹出窗口中使用zend删除操作? [英] How to use zend delete action in confirmation popup?

查看:156
本文介绍了如何在确认弹出窗口中使用zend删除操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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>

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

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 :)

推荐答案

您可以使用确认方法。

if (window.confirm('Are you sure you want to delete?'))
{
    window.location = "<?php echo $this->url('delete', array('action'=>'delete', 'id' => $articles->getId())) ?>"
}
else
{
    // do nothing
}

如果要使用jQuery UI对话框,

If you want to use jQuery UI dialog,

                        buttons: {
                            "Are you sure": function() {
                                window.location = "<?php echo $this->url('delete', array('action'=>'delete', 'id' => $articles->getId())) ?>"
                                $( this ).dialog( "close" );
                            },
                            Cancel: function() {
                                $( this ).dialog( "close" );
                            }
                        }

这篇关于如何在确认弹出窗口中使用zend删除操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆