【问题标题】:How to open view page in popup in yii2?如何在yii2的弹出窗口中打开查看页面?
【发布时间】:2018-07-17 01:56:50
【问题描述】:

我必须打开包含在弹出窗口而不是页面中的视图页面。单击视图后打开视图包含在 popupyii2

【问题讨论】:

    标签: php yii2


    【解决方案1】:

    您应该尝试使用此代码打开弹出窗口。您还需要使用此$this->renderAjax() 使用 ajax 视图进行渲染。

    控制器

    public function actionView($id)
    {
        if (Yii::$app->request->isAjax) {
            return $this->renderAjax('view', [
                'model' => $this->findModel($id),
            ]);
        } else {
            return $this->render('view', [
                'model' => $this->findModel($id),
            ]);
        }
    }
    

    查看

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
           ...................
            [
                'class' => 'yii\grid\ActionColumn',
                'buttons' => [
                    'view' => function ($url, $model) {
                                     return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $url , ['class' => 'view', 'data-pjax' => '0']);
                                },
                ],
     ....................
     ]); 
    
    $this->registerJs(
      "$(document).on('ready pjax:success', function() {  // 'pjax:success' use if you have used pjax
        $('.view').click(function(e){
           e.preventDefault();      
           $('#pModal').modal('show')
                      .find('.modal-content')
                      .load($(this).attr('href'));  
       });
    });
    ");
    
     yii\bootstrap\Modal::begin([
        'id'=>'pModal',
    ]);
     yii\bootstrap\Modal::end();
    ?>
    

    【讨论】:

    • 感谢这个工作,但如何取消这个弹出窗口和数据 id 不显示正确的格式
    • 输入以下代码以关闭弹出窗口&lt;button type="button" class="close" data-dismiss="modal"&gt; &lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;&lt;span class="sr-only"&gt;&lt;?= Yii::t('comm', 'Close') ?&gt;&lt;/span&gt; &lt;/button&gt;
    • jQuery.load() 加载整个网页(带有页眉和页脚)。这样,您需要为此视图创建一个特殊的布局,以便像部分渲染一样加载。
    • 查看 `yii\bootstrap\Modal` 上的页眉和页脚属性以获取更多信息。 @DanA.S.
    • 我说的是用$.load()和body一起加载的网页主布局的页眉和页脚
    猜你喜欢
    • 1970-01-01
    • 2023-03-06
    • 2016-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-31
    • 1970-01-01
    • 2012-06-03
    相关资源
    最近更新 更多