问题
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