I'm using Yii2 advanced, which have frontend and backend, I'm using two domain to access frontend and backend respectively.
For some reason, I add a baseUrl(/admin
) to backend, which will cause links like http://backend.example.com/controller/action
change to backend.example.com/admin/controller/action
, after this changing, the page can be load correctly
'components' => [
'request' => [
'csrfParam' => '_csrf-backend',
//All requests will add "/admin",e.g:
//backend.example.com/controller/action will change to
//backend.example.com/admin/controller/action
'baseUrl' => '/admin',
],
],
But it caused another problem: assets can't load cause it add /admin
too
I tried changing the baseUrl
of AppAssets
in backend/assets/AppAsset.php
, but not working
<?php
namespace backend\assets;
use yii\web\AssetBundle;
/**
* Main backend application asset bundle.
*/
class AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
'css/site.css',
];
public $js = [
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
];
}
It acts like $baseUrl
doesn't exists, no matter what value I set to $baseUrl
, the page just keep requesting /admin/assets/86321cf/xxxx.js
, how can I remove the /admin
by modifying settings in backend/assets/AppAsset.php
?
If I use the registerJsFile()
method to register js to the page
$this->registerJsFile('plugins/ImageViewer/imageviewer.min.js', ['position' => View::POS_END, 'depends'=>JqueryAsset::class]);
it's loading the correct path(which means not adding /admin
to the path)
So I was wondering how can I let the page load correct path of assets by changing configurations of backend/assets/AppAsset.php
or can I solve it by changing configurations in other file?