2016-10-03 113 views
0

在我的yii2項目中,我想獲取我的圖像複選框以便按圖像搜索。每當用戶選中複選框並提交按鈕時,它應該只顯示那些檢查圖像的內容。Yii2圖像將在搜索表單中有複選框列表

我的複選框列表

<?php $img = ArrayHelper::map(app\models\GhsPictogram::find()->all(), 'pictogram_id', 'pictogram_filepath') ?> 

    <?= $form->field($model, 'ghsPictogram',['template'=>'<div class="ghs-pict"> {label}{input} </div>'])->checkboxList($model->imageList($img)) ?> 

我的圖像列表的方法在我的模型

public function imageList($filenames) { 
     $imageList = []; 
     foreach ($filenames as $key => $value) { 
      $imageList[$key] = Html::img(
          Yii::$app->request->baseUrl . 'web' . $value, 
          '', array("style"=>"width: 50px") 
      ); 
     }//foreach $filenames 
     return $imageList; 
    } 

,但在我的形式,它不顯示圖像。它反而顯示圖像src。

我重視我的輸出: click here

幫我找到我怎麼能在搜索表單域顯示圖像。謝謝

回答

1

複選框列表有一個選項稱爲編碼,默認爲true,它編碼(如所述)傳遞給它的html。

爲了解決它,只需添加'encode' => true到CheckBoxList的選項屬性,像這樣:

<?= $form->field($model, 'ghsPictogram',['template'=>'<div class="ghs-pict"> {label}{input} </div>'])->checkboxList($model->imageList($img), [ 
    'encode' => false 
]) ?>