E
E
elfsfucker2015-10-08 14:09:34
Yii
elfsfucker, 2015-10-08 14:09:34

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]);
    }

Gallery.php view:
<?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>

Image.php view:
<?php
use yii\helpers\Html;
echo Html::img(Yii::$app->params['imagesUrl'] . $image->fileName, ['alt' => 'preview', 'class' => 'img text-center img-responsive']);

For some reason, the page is refreshing instead of displaying the image in full size.
There are no errors in the chrome developer tools in the console, in the network contribution these pjax requests are completely empty. But if you return just an image
in actionImage :
public function actionImage(){
        return "<img class='img text-center img-responsive'  src=".Yii::$app->params['imagesUrl'].$image->fileName.">";
    }

That all works, however it is impossible to do so, and it is very inconvenient.
Tell me, please, how to be and what am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
elfsfucker, 2015-10-08
@elfsfucker

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 question

Ask a Question

731 491 924 answers to any question