Search code examples
registrationyii2yii-url-managerurl-mapping

yii2 url managment/ correct registration of css and js files in a view


I've urlmanager turned on, and probably because of this fact I cannot register css and js fiels properly.

when I add $this->registerCssFile('views/A_view/A.css'); my file is attached <link href="D:\XAMPP\htdocs\somedomain.com/views/A_view/A.css" rel="stylesheet"> which seems correct. But the file is not really working on page. Further more if I'm trying to open it from debug of chrome in a new window browser goes to

http://somedomain.com/A_view/D:/XAMPP/htdocs/somedomain.com/views/A_view/A.css

Probably I have problems in url managment ? In urlManager settings I've got such rules like:

A_view/<username:\w+> => A_view/view
A_view => A_view/index
A_view/custom => A_view/custom
views/A_view => views/A_view

Shall I add something ?


Solution

  • As soju commented, it doesn't really have much to do with the urlmanager.

    It would be better to register your css and js files in an asset bundle, but you could also do:

    $this->registerCssFile(Yii::$app->request->baseUrl.'/views/A_view/A.css');