Yii2:如何在前端使用后端 Web 文件夹文件 [英] Yii2: How to use backend web folders files in frontend

查看:56
本文介绍了Yii2:如何在前端使用后端 Web 文件夹文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在后端 web 文件夹中有很多图片,我想在前端使用这些图片如何获取这些文件?

I have many images in backends web folder, I want to use those images in frontend how to get those files?

我需要显示 1 个(第一)图像,其路径保存在数据库中,如 Img1.jpg;img2.jpg;

I need to display 1 (first) image which path is saved in database like Img1.jpg;img2.jpg;

    <?php
      foreach (explode(';',rtrim($row['images'],';'),1) as $key_img => $value_img)
 {
  ?>

<?php echo  Html::img('@backend/web'.'/'.$value_img);?>                  

<?php
 }
?>

推荐答案

<?= \yii\helpers\Html::img('@backend/web/images/your-image.jpg') ?>

包含后端别名的 src 参数将由 Url::to()

The src parameter, containing the backend alias, will be processed by Url::to()

查看文档以了解 Html::img().

Check the docs for details on Html::img().

这篇关于Yii2:如何在前端使用后端 Web 文件夹文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆