lundi 3 octobre 2016

Yii2 images to have checkbox list in the search form

In my yii2 project I want to get checkbox for my images in order to search by images. Whenever the users checks the checkbox and submits the button, it should display the content only with those checked images.

My checkbox list

  <?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)) ?>

My imageList method in my model

   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;  
     }

But In my form it doesn't display the image. It instead displays the image src.

I have attached my output: click here

Help me find How can I display image in the search form field. Thank you

Aucun commentaire:

Enregistrer un commentaire