[php] show images
Viewer
- public function getPictures($picId) {
- $path = dirname(\Yii::$app->params['frontendUrl']."projects_pictures/{$picId}");
- $list = FileHelper::findFiles($path);
- foreach ($list as $pic) {
- $picsList[] = $pic;
- }
- return $picsList;
- }
- // actually the $path doesn't returned the required path to directory. it doesn't get {$picID} (which is an integer)
- //my view code
- DetailView::widget([
- 'model' => $model,
- 'attributes' => [
- 'name',
- 'project_date:date',
- 'client_name',
- 'project_url:url',
- 'detail:html',
- [
- 'attribute' => 'category_id',
- 'value' => $model->category->category_name, //we have getCategory() in Projects class, which returns a magic property 'category', through which we can access Category class attributes.
- ],
- [
- 'label' => "Category Image",
- 'value' => Yii::$app->params['frontendUrl'] . 'category/' . $model->category->category_name . '.jpeg',
- 'format' => ['image', ['width' => 100, 'height' => 100]]
- ],
- [
- 'label' => 'Project Images',
- 'format' => ['html'],
- 'value' => function ($model) {
- return $model->getPictures($model->id);
- }
- ]
- ],
- ])
Editor
You can edit this paste and save as new: