Image path issue in yii2

一个人想着一个人 提交于 2020-03-06 03:01:11

问题


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');

In Frontend/index.php

<body style="background-image:url(.<?Yii ::getAlias('@source') ?>.'/images/media-bg.jpg');background-attachment:fixed;">

Still getting Error (#2) .Please help


回答1:


You have some syntax error in this line:

<?Yii ::getAlias('@source') ?>

Replace with:

<?= Yii ::getAlias('@source') ?>

Set Alias(common/config/bootstrap.php):

Yii::setAlias('@root', realpath(dirname(__FILE__).'/../../'));

Get Alias:

Yii ::getAlias('@root');

Getting Uploaded image from project root directory

<img src="<?= Yii ::getAlias('@root').'uploads/images/cool.png';?> ">


来源:https://stackoverflow.com/questions/37202972/image-path-issue-in-yii2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!