无法使用 yii2 在滑块中显示图像
Can't show the image in slider with yii2
我有代码可以显示这样的视图
<div class="col-md-10">
<div class="col-md-4">
<?php
$items = [];
foreach ($team->gallery as $item){
$items[] = [
'content' => '<img style="width:300px;" src="'.$item->filepath.'"/>',
'caption' => '<h4>'.$item->name.'</h4><p>'.$item->description.'</p>',
];
}
echo Carousel::widget([
'items' => $items,
]);
?>
</div>
和像这样获取画廊的模型
public function getLeague(){
return $this->hasOne(Leagues::className(), ['id' => 'league_id']);
}
public function getGallery(){
return $this->hasMany(TeamGalleries::className(), ['team_id' => 'id']);
}
但是我无法在我的数据库中获取文件路径,因此我无法在我的网站上显示我的图片,如何解决这个问题?
我使用 yii2,上传图片的文件夹在 yii2 basic 的 web 文件夹中
如果您的图像在网络文件夹中,您可以轻松使用 Yii aliases,其中有一个条目用于此文件夹:@web
。
// Replace this
'<img style="width:300px;" src="'.$item->filepath.'"/>'
// with
'<img style="width:300px;" src="' . Yii::getAlias('@web') . '/' . $item->filepath . '"/>'
中有关别名的更多信息
我有代码可以显示这样的视图
<div class="col-md-10">
<div class="col-md-4">
<?php
$items = [];
foreach ($team->gallery as $item){
$items[] = [
'content' => '<img style="width:300px;" src="'.$item->filepath.'"/>',
'caption' => '<h4>'.$item->name.'</h4><p>'.$item->description.'</p>',
];
}
echo Carousel::widget([
'items' => $items,
]);
?>
</div>
和像这样获取画廊的模型
public function getLeague(){
return $this->hasOne(Leagues::className(), ['id' => 'league_id']);
}
public function getGallery(){
return $this->hasMany(TeamGalleries::className(), ['team_id' => 'id']);
}
但是我无法在我的数据库中获取文件路径,因此我无法在我的网站上显示我的图片,如何解决这个问题?
我使用 yii2,上传图片的文件夹在 yii2 basic 的 web 文件夹中
如果您的图像在网络文件夹中,您可以轻松使用 Yii aliases,其中有一个条目用于此文件夹:@web
。
// Replace this
'<img style="width:300px;" src="'.$item->filepath.'"/>'
// with
'<img style="width:300px;" src="' . Yii::getAlias('@web') . '/' . $item->filepath . '"/>'
中有关别名的更多信息