Answer the question
In order to leave comments, you need to log in
Why does pjax refresh the page?
I want to make a gallery based on pjax.
Controller:
public function actionGallery(){
$model = Gallery::find()->where(['thumbnail' => '1'])->orderBy(['position' => SORT_DESC])->all();
return $this->render('gallery', ['model' => $model]);
}
public function actionImage(){
$request = Yii::$app->request;
$image = Gallery::findOne($request->get('id'));
return $this->renderPartial('image', ['image' => $image]);
}
<?php
use yii\helpers\Html;
use yii\widgets\Pjax;
?>
<div class="row">
<?php
foreach ($model as $thumbnails) {
pjax::begin();
?>
<div class="">
<?php
echo Html::a(Html::img(Yii::$app->params['imagesUrl'] . 'thumbnails/' . $thumbnails->fileName,
['id' => $thumbnails->id,
'data' => ['method' => 'post'],
'alt' => 'preview',
'class' => 'img-responsive col-md-4 col-lg-3 col-sm-6 col-xs-12 imgBlock']),
['image', 'id' => $thumbnails->id], ['data-pjax' => '#' . $thumbnails->id]);
?>
</div>
<?php
pjax::end();
}
?>
</div>
<?php
use yii\helpers\Html;
echo Html::img(Yii::$app->params['imagesUrl'] . $image->fileName, ['alt' => 'preview', 'class' => 'img text-center img-responsive']);
public function actionImage(){
return "<img class='img text-center img-responsive' src=".Yii::$app->params['imagesUrl'].$image->fileName.">";
}
Answer the question
In order to leave comments, you need to log in
Setting the timeout helped:
Pjax::begin(['timeout' => 5000 ]);
https://github.com/yiisoft/yii2/issues/8819
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question