Hello. Trying to use CostaRico yii2-images . It has a "name" field in the database, in the settings of yii2-images this field is by default empty.

You can specify the name in the model

$model->attachImage('../../image2.png', true, myname); // myname - имя 

I get the main image like this:

 <?= Html::img($model->getImage()->getUrl())?> 

I get all the images like this:

 $images = $model->getImages(); foreach($images as $img){ <?= Html::img($img->getUrl())?>` } 

Tell me how to get me an image whose name = "myname"?

  • And what var_dump ($ images) will give; or print_r - Sergalas

1 answer 1

It seems to be so:

 <?= Html::img($model->getImageByName('myname')->getUrl()) ?> 

I did not check it, I just discovered this method there: tyts

  • You, my joy: thanks! - firebear
  • @firebear Well mark then too the answer as a solution) - pa3py6aka