[php] link generation

Viewer

copydownloadembedprintName: link generation
  1. //my view file code
  2. DetailView::widget([
  3.         'model' => $model,
  4.         'attributes' => [
  5.             'name',
  6.             'project_date:date',
  7.             'client_name',
  8.             'project_url:url',
  9.             'detail:html',
  10.             [
  11.                 'attribute' => 'category_id',
  12.                 'value' => $model->category_id ? $model->category->category_name : "Category not selected" //we have getCategory() in Projects class, which returns a magic property 'category', through which we can access Category class attributes.
  13.             ],
  14.             [
  15.                 'label' => 'Project Images',
  16.                 'format' => ['raw'], 
  17.                 'value' =>  $this->render('_test', ['listData' => $model])
  18.             ]
  19.         ],
  20.     ])
  21.     
  22.     // my _test.php file code
  23.     $link = Yii::getAlias('@frontend/web/projects_pictures/'.$listData->id);
  24.     $path = \yii\helpers\FileHelper::findFiles($link);
  25.     foreach ($path as $pic){
  26.         echo "<img src='$pic' alt='test' />";
  27.     }

Editor

You can edit this paste and save as new: