2014-03-27 223 views

回答

13

可以定義爲細胞類如實施例

[ 
    'attribute' => 'title', 
    'format' => 'image', 
    'value' => function($data) { return 'you_image.jpeg'; }, 
    'contentOptions' => ['class' => 'come-class'] 
], 

然後設置圖像寬度使用CSS英寸如果圖像寬度可以是不同的,使用HTML格式

[ 
    'attribute' => 'title', 
    'format' => 'html', 
    'value' => function($data) { return Html::img('you_image.jpeg', ['width'=>'100']); }, 
], 
+0

@kopletusprime @Alex不適合我。我有''value'=>函數($ data){return $ data-> imageurl; }',它不是一個靜態圖片網址。那麼我在哪裏放''[width'=>'100']'???我嘗試了一切,我認爲它適合,但我得到錯誤 – kaynewilder

+0

指出你的錯誤 –

2

用途:

'value' => function($data) { 
     return Html::img($data->imageurl,['width'=>100]); 
    }, 

而在你的模型:

/* 
    Return Image url path 
    */ 
    public function getimageurl() 
    { 
     // return your image url here 
     return \Yii::$app->request->BaseUrl.'/uploads/'.$this->ImagePath; 
    } 
1

使用

'format' => ['image',['width'=>'100','height'=>'100']], 

例如:

[   
     'attribute' => 'image', 
     'format' => ['image',['width'=>'100','height'=>'100']], 
     'value' => function($dataProvider) { return $dataProvide->image; }, 


], 
相關問題