答案 0 :(得分:4)
您应该尝试使用此代码打开弹出窗口。并且您还需要使用此$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();
?>