I have to open view page contain in popup instead of page.After click on view open view contain in popup yii2
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You should try this code for opening popup. and also you need to render with ajax view using this $this->renderAjax()
.
controller
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),
]);
}
}
View
<?= 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();
?>