【发布时间】:2014-03-26 07:24:46
【问题描述】:
我想使用确认弹出窗口来删除我的项目,所以这是我的删除操作:
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="<?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 视图,我想要的是在我确认弹出窗口时删除该项目。
所以如果有人有任何解决方案,我将非常感激:)
【问题讨论】:
-
这个问题的答案正如@emaillenin 提到的那样,
document.form.submit();行被删除并在$(this).dialog( "close" );之后添加window.location.href = ....
标签: php jquery zend-framework doctrine-orm zend-framework2