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
.
通常我也会从前端/网络/图片到后端/网络/图片
从前端显示后端的图片。
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.