Yii2: path issue when redirecting using pretty login url

I included a pretty url in the url manager and tried logging in. When the logs work successfully on my toolbar, I get problems with wrt CSS and loading JS for this page, since the path creates a problem. I analyzed the problem in a network problem, screenshot below.

The first screenshot is the image when I try to log in without using pretty UR ... works fine How to fix this problem.

Second: this is the login page when I included a pretty url and opened the login window

Thirdly: This is the third image when I enter the journal where the path problem occurs. the path for loading css and JS is different and therefore I get a 404 error in the network panel

+6
source share
1 answer

This is not particularly relevant to the fact that your urlManager is enabled, but rather how you register your assets.

You can simply add js and css files to your Asset Bundle, for example. /frontend/assets/AppAssets.php and make sure your package is published in a layout file, for example. /frontend/views/layout/main.php .

You can also try:

 $this->registerJsFile(Yii::$app->request->baseUrl.'/js/plugins/sparkline/jquery.sparkline.min.js'); 

Instead

 $this->registerJsFile('js/plugins/sparkline/jquery.sparkline.min.js'); 

which is looking for a file relative to the url, so it does not work with urlManager enabled.

+1
source

Source: https://habr.com/ru/post/980762/


All Articles