Yii2:从文件夹常见显示图像 [英] Yii2 : Show image from Folder Common

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

问题描述

我想在视图中显示常用文件夹中的图片,但它没有显示。

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

我的代码是:

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

它生成为< img src =/ simdsm / common / web / ava.jpgclass =img-responsive> 但图片没有出现。

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

如何解决?

推荐答案

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

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

通常我也会从<$ c创建别名$ c>前端/网络/图片到后端/网络/图片从前端显示后端的图片。

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

您提到的不是Web可访问目录。

What you mentioned is not web accessible directory.

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

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天全站免登陆