Yii Framework Forum: Error on open image in page - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Error on open image in page (Open as base64)

#1 User is offline   Gustavo Andrade 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 200
  • Joined: 16-August 11
  • Location:Brazil - MG

Posted 11 May 2017 - 07:52 PM

Hi,

I have a gridview with pjax, which does the listing of images. But when you click on the image to open it, it opens it in the base64 format (everything is encoded on the page).

How to correct?

Viewing the image

Attached File  PeTZ2.png (58.84K)
Number of downloads: 0
https://ibb.co/jxnVo5


After clicking

Attached File  VYu3G.png (62.9K)
Number of downloads: 0
https://ibb.co/dGWqo5

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"], ['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() ?>

-------------------------------------
https://github.com/gugoan
0

#2 User is offline   Gustavo Andrade 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 200
  • Joined: 16-August 11
  • Location:Brazil - MG

Posted 13 May 2017 - 02:07 PM

Fix with param
'data-method'=>'post'




[
                	'attribute'=>'img',
                	'format' => 'raw',
                	'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'],
                	],

-------------------------------------
https://github.com/gugoan
0

#3 User is offline   Roberto Braga 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 186
  • Joined: 18-February 13
  • Location:Roma, Italy

Posted 14 May 2017 - 01:52 AM

The IMG tag normally link a file that the browser download and show in the page.
It seem to me that you are trying to embeb it directly in to the HTML.
Altrougth is possible, read the following link for the correct way,
http://www.techerato...into-your-html/
I would avoid that since these images change and this prevent the browser to cache the contents.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users