Zend Framework 2和jQuery模态对话框 [英] Zend Framework 2 & jquery modal dialog
问题描述
如何在jquery模式对话框中显示控制器动作?
How does one go about displaying a controller action inside of jquery modal dialog?
推荐答案
首先,您需要Javascript通过ajax加载url,这取决于您使用的是哪种模式,等等,这里有大量的库那里.我假设您使用的是基本的JQuery UI对话框模式.
Firstly you'll need your Javascript to load a url via ajax, this will depend on which kind of modal you are using etc, there's a ton of libraries out there. I will assume you are using the basic JQuery UI dialog Modal.
示例链接
<!-- this points to your action below.. -->
<a class="some-link" title="title here" href="mycontroller/test">testing</a>
示例Javascript(可在Google上找到快速示例,那里有许多示例.)
Example Javascript (quick example found on google, many examples out there..)
$(document).ready(function() {
$('.some-link').each(function() {
var $link = $(this);
var $dialog = $('<div></div>')
.load($link.attr('href'))
.dialog({
autoOpen: false,
title: $link.attr('title'),
});
});
});
现在,当通过ajax请求提供模态的内容时,您需要确保您的操作不会呈现主布局.
Now you need to make sure your action doesn't render the main layout when providing the content for the modal via the ajax request.
这是一个非常简单的方法,通过用空视图替换ajax请求的基本布局来做到这一点.这不是最好的方法,但在这种情况下是最简单的方法;)
Here's a really simple method of doing that by replacing the base layout with an empty view for ajax requests. This isn't the best method but it's the simplest for this case ;)
示例动作
public function testAction()
{
if($this->getRequest()->isXmlHttpRequest()) {
$this->layout('application/layout/ajax-layout');
}
return new ViewModel(array()); // ..
}
application/layout/ajax-layout.phtml
application/layout/ajax-layout.phtml
<?php echo $this->content ?>
这篇关于Zend Framework 2和jQuery模态对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!