Yii2:如何在数据库中保存的路径中显示多个图像?

时间:2016-02-11 07:44:22

标签: yii2 yii2-advanced-app

我在数据库中有一个名为images的列,其中包含图像路径。

查询:

$query = new Query;
                $todo = (new yii\db\Query())
                ->select(['images'])
                ->from('room_types')
                ->andWhere("id = '$model->id'")
                ->all();

查看:

<?php
foreach ($todo as $row)
{
?>
<?php echo Yii::getAlias('@web').'/'.$row; ?>
<?php
}
?>

db:中保存的图像路径

uploads/room_img/30.jpg;uploads/room_img/300.jpg;uploads/room_img/11928_569674493052762_732198968_n.jpg;

尝试使用explode():

<?php 

function room_images() {
        $query = mysql_query("SELECT images FROM room_types WHERE id = $model->id");
        while($row = mysql_fetch_array($query)) {
            $e[] = explode(" ", $row[0]);
            foreach($e as $r) {
                echo $r;
            }
        }
    }

 ?>

但没有显示

1 个答案:

答案 0 :(得分:2)

使用getParameterByName()类的img方法 - reference

在您的视图文件中

Html