yii2 中的图像路径问题 [英] Image path issue in yii2
问题描述
我的 yii2 项目中有前端、后端和 API.我已经从 url 中删除了前端/网络.我按照以下帖子进行操作.http://www.yiiframework.com/wiki/755/how-to-hide-frontend-web-in-url-addresses-on-apache/但是我的整个图像在后端和前端都没有找到错误.我在提供路径时遇到问题.我尝试了以下代码在 params-local.php
I have frontend,backend and API's in my yii2 project.I have remove front/web from url.I follow following post for that. http://www.yiiframework.com/wiki/755/how-to-hide-frontend-web-in-url-addresses-on-apache/ But my entire images getting not found error in backend and frontend.I am facing problem to give path.I have tried following code In params-local.php
Yii ::setAlias('@source', 'http://example.com');
在前端/index.php
In Frontend/index.php
<body style="background-image:url(.<?Yii ::getAlias('@source') ?>.'/images/media-bg.jpg');background-attachment:fixed;">
仍然出现错误(#2).请帮忙
Still getting Error (#2) .Please help
推荐答案
你在这一行有一些语法错误:
You have some syntax error in this line:
<?Yii ::getAlias('@source') ?>
替换为:
<?= Yii ::getAlias('@source') ?>
设置别名(common/config/bootstrap.php):
Set Alias(common/config/bootstrap.php):
Yii::setAlias('@root', realpath(dirname(__FILE__).'/../../'));
获取别名:
Yii ::getAlias('@root');
从项目根目录获取上传的图片
Getting Uploaded image from project root directory
<img src="<?= Yii ::getAlias('@root').'uploads/images/cool.png';?> ">
这篇关于yii2 中的图像路径问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!