2016-09-26 73 views
1

這是我的小夥子。如何在yii框架中設置圖像路徑?

<?=Html::img('file_path',['alt' => 'class room'])?> 

我的圖片真實路徑是web/image/class.jpg。如何在file_path中設置路徑。

任何人都知道如何解決我的問題?

在此先感謝!

回答

1

你可以使用Yii :: $ app-> request-> baseUrl;

<?=Html::img(Yii::$app->request->baseUrl; . 'file_path',['alt' => 'class room'])?> 

可能是你需要/圖像/

<?=Html::img(Yii::$app->request->baseUrl; . '/image/' . 'file_path',['alt' => 'class room'])?> 

看到更多http://www.yiiframework.com/doc-2.0/guide-helper-url.html

您可以@web可能會嘗試......但不是 'FILE_PATH' ..你需要$模型 - >屬性引用

<?= Html::img('@web/image/' . $model->file_path , ['alt' => 'class room']) ?> 
+0

感謝您迴應me.But它不是正在工作 –

+0

file_path是web/images/class.jpg。 –

+0

<?= Html :: img(Url :: home(true)。'/ image /'。'web/images/class.jpg',['alt'=>'class room'])?>是否正確?? –

1

試試這個:

<img src="<?=Yii::$app->request->baseUrl?>/image/class.jpg"> 

的Yii :: $ APP->請求 - >的baseUrl:它從根返回路徑網絡

或者您也可以使用

<img src="<?=Yii::getAlias('@web'); ?>/image/class.jpg"> 
+0

謝謝你回覆我。但不工作。我是yii的初學者。 –

+0

什麼顯示.. –

+0

什麼都沒有。我的意思是其他文字和按鈕是節目。但不是一個圖像。 –