1

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();
                            }
                        );
                });");
vijay nathji
  • 1,608
  • 13
  • 23
  • 1
    What have you tried? Do your own research first and post the problems you encounter here. StackOverflow is here to help us learn, not do the work for us. – Ianthe the Duke of Nukem May 17 '16 at 05:13
  • @Ianthe the Duke of Nukem : I had asked for suggestion not for work. :) Please check my edited question. i have used Yii2 modal dialog box. but not working when i expand grid. can u pls suggest any idea on this. thanks in advance – vijay nathji May 17 '16 at 05:27
  • Used Modal dialog Modal::begin([ 'id' => 'imageview', 'footer' => 'Close', ]); Modal::end(); – vijay nathji May 17 '16 at 05:31
  • Is you image path is correct? like `http://localhost/yii2-app/uploades/cool.png` – Muhammad Shahzad May 17 '16 at 06:28
  • @Muhammad Shahzad : Yes path is perfect. As i see view source the path of image in corret but not loading in popup – vijay nathji May 17 '16 at 11:31

1 Answers1

1

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();

vijay nathji
  • 1,608
  • 13
  • 23