Yii2 : 显示来自常用文件夹的图像 [英] Yii2 : Show image from Folder Common

查看:18
本文介绍了Yii2 : 显示来自常用文件夹的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在公共文件夹中显示一张图片,但没有显示.

我的代码是:

<img src="<?= Yii::$app->request->baseUrl .'/common/web/img/ava.jpg' ?>"class="img-responsive" >

它被生成为 <img src="/simdsm/common/web/ava.jpg" class=" img-responsive"> 但图像没有出现.

如何解决?

解决方案

如果使用高级应用程序模板,图像应放置在这些 Web 可访问文件夹中 - frontend/webbackend/web.

通常我还会创建从 frontend/web/imagesbackend/web/images 的别名,以便从前端在后端显示图像.

您提到的不是网络可访问目录.

从此类目录发布图像的另一种方法是为该文件夹创建资产包,例如,图像将复制到 frontend/web/assets 中.您可以在官方文档中阅读有关资产包的更多信息.>

I have a picture in folder common that i want to show in view, but it doesn't shown.

My code is :

<img src="<?= Yii::$app->request->baseUrl . '/common/web/img/ava.jpg' ?>" class=" img-responsive" >

It's generated to be <img src="/simdsm/common/web/ava.jpg" class=" img-responsive"> but the image does not appear.

How to fix it?

解决方案

In case of using advanced application template, images should be placed in these web accessible folders - frontend/web or backend/web.

Also usually I create alias from frontend/web/images to backend/web/images to display images in backend from frontend.

What you mentioned is not web accessible directory.

Alternative way to publish images from such directory will be creating asset bundle for that folder, that way images will be copied in frontend/web/assets for example. You can read more about asset bundles in official docs.

这篇关于Yii2 : 显示来自常用文件夹的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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