如何在yii2的弹出窗口中打开查看页面? [英] How to open view page in popup in yii2?
本文介绍了如何在yii2的弹出窗口中打开查看页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须打开包含在弹出窗口而不是页面中的视图页面.点击查看后,在弹出窗口中打开视图 yii2
I have to open view page contain in popup instead of page.After click on view open view contain in popup yii2
推荐答案
你应该试试这个打开弹出窗口的代码.并且您还需要使用此 $this->renderAjax()
使用 ajax 视图进行渲染.
You should try this code for opening popup. and also you need to render with ajax view using this $this->renderAjax()
.
控制器
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();
?>
这篇关于如何在yii2的弹出窗口中打开查看页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文