3

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 ?

4

2 回答 2

3

正如烧酒评论的那样,它与 urlmanager 并没有太大关系。

最好在资产包中注册您的 css 和 js 文件,但您也可以这样做:

$this->registerCssFile(Yii::$app->request->baseUrl.'/views/A_view/A.css'); 
于 2014-12-30T19:39:24.717 回答
2

为了补充其他答案,这些天您还可以使用@web

$this->registerCssFile('@web/views/A_view/A.css');

它使代码更简洁。

于 2015-10-01T19:06:57.617 回答