简体   繁体   English

Yii2-模态未加载内容

[英]Yii2 - Modal not loading content

I am having a problem with modal window loading on staging server. 我在登台服务器上加载模式窗口时遇到问题。 Where my modal windows load on localhost (Apache) they fail to load content on staging (LiteSpeed). 我的模态窗口在本地主机(Apache)上加载的位置无法在暂存(LiteSpeed)上加载内容。 What is strange is that the modal opens and shows header, but no content. 奇怪的是,模式打开并显示标题,但没有内容。 I get 503 error when I inspect elements. 检查元素时出现503错误。

Staging also doesn't load favicon. 暂存也不会加载网站图标。 I suppose the problem is somewhere in configuration, but as I am just starting with Yii2, I don't know where to look anymore. 我想问题出在配置中,但是由于我只是从Yii2开始,所以我不知道在哪里看。

I have created the modal functionality as follows: 我创建了模态功能,如下所示:

modal.js in web/js/modal.js web / js / modal.js中的modal.js

$(function(){
$(document).on('click', '.showModalButton', function(){
    if ($('#modal').data('bs.modal').isShown) {
        $('#modal').find('#modalContent')
            .load($(this).attr('value'));
        //dynamically set the header for the modal
        document.getElementById('modalHeader').innerHTML = '<button type="button" class="close" ' +
                                                                'data-dismiss="modal" aria-label="Close">' +
                                                                '<span aria-hidden="true">&times;</span>' +
                                                           '</button> ' +
                                                           '<h4>' + $(this).attr('title') + '</h4>';
    } else {
        $('#modal').modal('show')
            .find('#modalContent')
            .load($(this).attr('value'));
        //dynamically set the header for the modal
        document.getElementById('modalHeader').innerHTML = '<button type="button" class="close" ' +
                                                                'data-dismiss="modal" aria-label="Close">' +
                                                                '<span aria-hidden="true">&times;</span>' +
                                                           '</button> ' +
                                                           '<h4>' + $(this).attr('title') + '</h4>';
    }
});
});

Layout set in views/layouts/main.php (excerpt) 在views / layouts / main.php中设置的布局(节选)

</footer>

<?php
Modal::begin([
    'headerOptions' => [
        'id' => 'modalHeader',
    ],
    //'footer' => '<a href="#" class="btn btn-primary" data-dismiss="modal">Close</a>',
    'id' => 'modal',
    'size' => 'modal-lg',
    //keeps from closing modal with esc key or by clicking out of the modal.
    // user must click cancel or X to close
    'clientOptions' => [
        'backdrop' => 'static',
        'keyboard' => false
    ],
]);

echo "<div id='modalContent'></div>";

Modal::end();
?>

<?php $this->endBody() ?>

View for index action (excerpt) 查看索引操作(节选)

<p>
    <?= Html::a('Create FAQ',
        false,
        [
            'class' => 'showModalButton btn btn-success',
            'value' => '/index.html?r=faq/create',
            'title' => 'Create FAQ',
        ]) ?>
</p>

When I press button modal opens,but doesn't load the form. 当我按下按钮时,模式打开,但不加载表格。

If I missed some important information, please ask if it can shed light to this issue. 如果我错过了一些重要信息,请询问是否可以阐明此问题。

The page loads all the assets and I get the 503 error only on staging server. 该页面将加载所有资产,并且仅在登台服务器上出现503错误。

这是本地主机上的工作模式

这是登台服务器上的非工作模式

use yii\bootstrap\Modal;

in your Grid View 
'panel' => [
         'before' => Html::a('<i class="glyphicon glyphicon-plus">Open Modal</i>', ['#'], ['data-toggle' => 'modal', 'class' => 'btn btn-md btn-success', 'data-target' => '#showModal']),
        'type' => GridView::TYPE_PRIMARY,
]

At the bottom add this 

Modal::begin([
    'id' => 'showModal',
    'header' => '<center><h4 class="modal-title">Allocate Work </h4></center>',
    'closeButton' => [
                  'label' => 'Close',
                  'class' => 'btn btn-danger btn-sm pull-right',
                ],


]);
echo Yii::$app->controller->renderPartial('allocation');
 Modal::end();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM