[php] show images

Viewer

copydownloadembedprintName: show images
  1. public function getPictures($picId) {
  2.         $path = dirname(\Yii::$app->params['frontendUrl']."projects_pictures/{$picId}");
  3.         $list = FileHelper::findFiles($path);
  4.         foreach ($list as $pic) {
  5.             $picsList[] = $pic;
  6.         }
  7.         return $picsList;
  8.     }
  9.     
  10.     // actually the $path doesn't returned the required path to directory. it doesn't get {$picID} (which is an integer)
  11.     
  12.     
  13.     //my view code
  14.     DetailView::widget([
  15.         'model' => $model,
  16.         'attributes' => [
  17.             'name',
  18.             'project_date:date',
  19.             'client_name',
  20.             'project_url:url',
  21.             'detail:html',
  22.             [
  23.                 'attribute' => 'category_id',
  24.                 'value' => $model->category->category_name,
  25.             ],
  26.             [
  27.                 'label' => "Category Image",
  28.                 'value' => Yii::$app->params['frontendUrl'] . 'category/' . $model->category->category_name . '.jpeg',
  29.                 'format' => ['image', ['width' => 100, 'height' => 100]]
  30.             ],
  31.             [
  32.                 'label' => 'Project Images',
  33.                 'format' => ['image'],
  34.                 'value' => function ($model) {
  35.                     return $model->getPictures($model->id);
  36.                 }
  37.             ]
  38.         ],
  39.     ])

Editor

You can edit this paste and save as new: