How to display images

Hello. I am new in Yii and php frameworks. Sorry for my English.

I use Advanced layout. I created a CRUD (for goods) in the backend and added there image field. I’ve already created the form and uploading model. Now I want to render that image in backend (for admins) and frontend (for users). How to make this image accessable from frontend and backend? I’ll be glad to see working example.

basically:


<?= Html::img('images/test.jpeg');?>

Or in model/Detailview for example:


[ 	'attribute'=>'photo', 	'value'=>$model->photo, 	'format' => ['image',['width'=>'100','height'=>'100']], ],

:)

Gustavo Andrade, Thanks for reply. Can you show me the model and controller. I am not sure about my code(about $model->photo and uploading path)

Hi

Sure, you want to display the image where? Detailview or Gridview ?

Gridview

Right,

For example:

Gridview


[     'format' => 'image',     'value' => function ($model) {         return $model->getImageUrl();      }, ],

Model


public function getImageUrl() {     return Url::to('@web/path/to/logo/' . $this->logo, true); }

http://stackoverflow.com/questions/21880511/image-in-gridview-in-yii2

http://stackoverflow.com/questions/22677501/set-width-image-in-gridview-yii2