2016-10-03 35 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 
]) ?>