Search code examples
yiiyii2yii-extensionsyii2-advanced-appyii-components

Yii2 Image Popup in kartik gridview


I need help in displaying image in Kartik gridview Yii2.

Please give me suggestion to show image in popup when we click on it.

/* Script to load the image in popup */

  'attribute' => 'image',
        'width' => '50px',
        'value' => function ($model, $key, $index, $widget) {
            if ($model->image != '') {
                return Html::a(Html::img(Yii::$app->params['server'] . "/mypath/uploadedfile/" .
                                        Yii::$app->session['city'] . "/" . $model->image, ['width' => '70px', 'height' => '70px']), '#', [
                            'title' => Yii::t('app', 'View Image'),
                            'class' => 'view-image-link',
                            'data-id' => $model->image,
                ]);
            } else {
                return "No Image";
            }


            $this->registerJs("    
                $('.view-image-link').click(function()
                {
                    $.get
                        (
                            'viewimage',
                            {
                                id: $(this).data('id')
                            },
                            function(data) 
                            {
                                $('.modal-body').html(data);
                                $('#imageview').modal();
                            }
                        );
                });");

Solution

  • By Changing I have resolved my self

    Modal dialog Modal::begin([ 'id' => 'imageview', 'footer' => '<a href="#" class="btn btn-sm btn-primary" data-dismiss="modal">Close</a>', ]); Modal::end();