页面中打开图像时出错(以base64身份打开)

时间:2017-05-10 18:28:49

标签: gridview yii2

我有一个带有pjax的gridview,它可以处理图像列表。但是当您单击图像打开它时,它会以base64格式打开它(所有内容都在页面上编码)。

如何纠正?

查看图片 enter image description here 点击enter image description here

UPDATED POST page.php

<?php Pjax::begin(['id' => 'pjax-container']) ?>
            <?= GridView::widget([
            'dataProvider' => $dataProvider,
            'emptyText'    => '</br><p class="text-danger">Nenhum imagem anexada!</p>',
            'summary'      =>  '',
            'showHeader'   => false,
            'columns' => [
                    [
                    'attribute'=>'img',
                    'format' => 'html',
                    'value'=>function ($data) {
                        return Html::a(Html::img(\Yii::$app->getModule('client')->params['clientImages'].$data["mod_client_base_id"].'/'.$data["img"],
                             ['width' => '50px', 'class' => 'img-rounded img-responsive']), \Yii::$app->getModule('client')->params['clientImages'].$data["mod_client_base_id"].'/'.$data["img"], ['data-method'=>'post','target' => '_blank']);
                    },                                     
                    'contentOptions'=>['style'=>'width: 70%;text-align:left'],
                    ],
                    [
                    'class' => 'yii\grid\ActionColumn',
                    'contentOptions'=>['style'=>'width: 30%;text-align:center'],
                    'controller' => 'images',
                    'template' => ' {delete}',
                    'buttons' => [
                            'delete' => function ($url) {
                            return Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, [
                              'title' => 'Excluir Imagem',
                              'class' => 'btn btn-default btn-sm',
                              'aria-label' => 'Excluir',
                              'onclick' => "
                                  if (confirm('Tem certeza que deseja excluir?')) {
                                      $.ajax('$url', {
                                          type: 'POST'
                                      }).done(function(data) {
                                          $.pjax.reload({container: '#pjax-container'});
                                      });
                                  }
                                  return false;
                              ",
                            ]);
                            },
                    ],
                ],
            ],
            ]); ?>
<?php Pjax::end() ?>

1 个答案:

答案 0 :(得分:0)

修复:'data-method'=>'post'

[
                    'attribute'=>'img',
                    'format' => 'html',
                    'value'=>function ($data) {
                        return Html::a(Html::img(\Yii::$app->getModule('client')->params['clientImages'].$data["mod_client_base_id"].'/'.$data["img"],
                             ['width' => '50px', 'class' => 'img-rounded img-responsive']), \Yii::$app->getModule('client')->params['clientImages'].$data["mod_client_base_id"].'/'.$data["img"], ['data-method'=>'post','target' => '_blank']);
                    },                                     
                    'contentOptions'=>['style'=>'width: 70%;text-align:left'],
                    ],