Image path issue in yii2

2019-09-12 07:29发布

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

标签: php url yii2
1条回答
一夜七次
2楼-- · 2019-09-12 08:04

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';?> ">
查看更多
登录 后发表回答