簡體   English   中英

在CDetailView Yii框架中顯示多個圖像/鏈接

[英]Display Multiple Images/Links In CDetailView Yii framework

幫助我整天都在沖浪,找不到主題如何在CDetailView中顯示多個圖像。 我的情況如下:

  1. 我上傳了多個圖像,圖像jpg文件存儲在/ images / doc目錄中。
  2. 我已經輸入了單元格中圖像的路徑,這意味着該單元格包含三個用逗號分隔的文件名:abc.jpg,xyz.jpg,abaca.jpg。
  3. 我想在CDetailView中顯示鏈接,該鏈接可單擊以在新標簽頁瀏覽器中打開圖像。

我已經嘗試過使用此腳本:

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

這也可以顯示圖像

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

在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]
            ),

但是當我單擊瀏覽器無法識別的鏈接時,結果卻沒有預期。

我希望得到這樣的結果:它應該是動態形式,可能正在使用“ foreach”語句如何使用它,而我卻沒有得到它……

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

……

請幫助有關

Sandeep

如果我理解您的觀點,那么您需要每行有多張圖片,對嗎?

對值屬性具有unanymouse函數,並返回圖像的鏈接:

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

感謝您的幫助,這是最簡單,最好的方法。

模型中的功能

public function getDocument($model)
{
    $link = '';
    $attribute=CHtml::encode($model->documents);
    $file = str_getcsv($attribute ,",");
    if(!empty($model->documents))
    foreach($file as $i=> $record)
    {
        $link .= CHtml::link(CHtml::encode($file[$i]),Yii::app()->baseURL . '/Documents/' . $file[$i]) . '<br />';
    }
    return $link;
}

在視圖小部件CDetailView

array(
    'name'=>"Uploaded Document ",
    'value'=> $model->getDocument($model),
    'type'=>'raw'   
    ),

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM