Search code examples
phpyiicdetailview

Display Multiple Images/Links In CDetailView Yii framework


Help I have been surfing all day and can not find the topic, how to display multiple images in CDetailView. My situation are as follows:

  1. I have uploaded multiple images, the image jpg files stored in /images/doc directory.
  2. I have entried path to the images in a cell, means the cell contain three filenames with comma separated: abc.jpg, xyz.jpg, abaca.jpg.
  3. I wanna to display the link in CDetailView which clickable to open the image in new tab browser.

I have tried with this script:

array(
                    'name'=>'File Link',
                    'type'=>'raw',
                    'value'=> Links of abc,  
                                       xyz,

and also this to display the images

$document= CHtml::encode($model->Document);
$file = str_getcsv($document ,",");

in CDetailView

    array(
            'name'=>'Image',
            'type'=>'raw',
            'value'=>link to $file[1]
            ),

 array(
            'name'=>'Image',
            'type'=>'raw',
            'value'=>link to $file[2]
            ),

 array(
            'name'=>'Image',
            'type'=>'raw',
            'value'=>link to $file[3]
            ),

but the result is not as I expected, when I click the link unrecognized opened by the browser.

I expect result like this: and it should be in Dynamic form may be using 'foreach' statement how to use it i m not getting it ... ...

File Link : abc.jpg
                xyz.jpg
                abaca.jpg <== each must be clickable to the location of the image

... ...

Please Help Regards

sandeep


Solution

  • If I understand your point, you need to have multiple images per row, right?

    have a unanymouse function for value attribute and return the link of images:

    'value' => function($data){ // here $data represents your model
       $link = '';
       if(!empty($data->images))
           foreach($data->links as $l)
           {
               $link .= CHtml::link(CHtml::encode($file[$i]),Yii::app()->baseUrl . '/images/' . $file[$i]) . '<br />';
           }
       return $link;
    }