Zend Framework 2 & jquery modal dialog

南楼画角 提交于 2019-12-05 07:49:28

问题


How does one go about displaying a controller action inside of jquery modal dialog?


回答1:


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.

Example Link

<!-- this points to your action below.. -->
<a class="some-link" title="title here" href="mycontroller/test">testing</a>

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

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.

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

Example Action

public function testAction()
{
    if($this->getRequest()->isXmlHttpRequest()) {
        $this->layout('application/layout/ajax-layout');
    }

    return new ViewModel(array()); // ..
}

application/layout/ajax-layout.phtml

<?php echo $this->content ?>



回答2:


I think you want this kind of code http://jqueryui.com/dialog/#modal-message inside the just display your action

Otherwise it's about to open an url into your modal it's like that http://blog.nemikor.com/2009/04/18/loading-a-page-into-a-dialog/



来源:https://stackoverflow.com/questions/16192702/zend-framework-2-jquery-modal-dialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!