SOLVED: How to insert an Image List into a radioButtonList?

Hi all,

I have a problem figuring out how to load a list of images in a radioButtonList (if it’s possible) since I have a model Photos for the database table Photos(Id, Filename).

I want to use that model in the view of another model in which there is an IdPhotos (foreign key). I tried this code as a start :


<div class="row">

        <?php echo $form->labelEx($model, 'Idphotos'); ?>

        <?php echo $form->radioButtonList(

                $model,

                'Idphotos',

                Photos::model()->findAll(),

                array('separator' => '')

                ); ?>

        <?php echo $form->error($model, 'Idphotos'); ?>

    </div>



But it won’t show the images. Is there an easy way to achieve this?

Thanks.

Found a way to solve this need :

I added this function in the model




    /**

 	* @return string[] an image list for the photos

 	* @param string[] $filenames

 	*/

    public function imageList($filenames) {

        $imageList = array();

        foreach ($filenames as $key => $value) {

            $imageList[$key] = CHtml::image(

                            Yii::app()->baseUrl . Yii::app()->params['ImagesFolder'] . $value,

                            $value

            );

        }//foreach $filenames

        return $imageList;

    }



then called it from the view :




    <div class="row">

        <?php echo $form->labelEx($model, 'Idphotos'); ?>

        <?php

        echo $form->radioButtonList(

                $model,

                'Idphotos',

                $model->imageList(CHtml::listData(

                                Photos::model()->findAll(),

                                'Id',

                                'Filename'

                        )

                ),

                array('separator' => '')

        );

        ?>

        <?php echo $form->error($model, 'Idphotos'); ?>

    </div>



Done!

Brilliance, save me a lots time, thx.