Yii 2.0 模板怎么引入 CSS 和 JS 文件? [ 新手入门 ]
比如我在 web 文件夹下建立 css 文件和 js 文件。在 assets 建立资源控制器。那么我在 view 层的时候怎么调用 web/css
或者 web/js
文件呀。求解答不胜感激
共 19 条回复
-
-
-
-
-
<?php use yii\helpers\Html; use app\assets\AppAsset; use yii\widgets\ActiveForm; use yii\captcha\Captcha; /* @var $this \yii\web\View */ /* @var $content string */ AppAsset::register($this); // here $this->registerJsFile("@web/assets/1b5abb4b/jquery-1.js"); ?>
共 1 条回复 -
kaler_mosen 回复于 2014-12-27 03:30 举报
用了
AppAsset::register($this);
但是没有生成link啊。就是没有成功引入css或js文件,求解,请问你有自己试过吗?
如果用$this->registerJsFile("@web/assets/1b5abb4b/jquery-1.js");
那就还要一个个写,那要资源管理器干嘛。。。猴猴吖 觉得很赞 -
-
-
-
同样的问题,再backend的login页面没有使用layout,注册asset后,没有在页面加载css的相关代码。
共 1 条回复我刚好用到这个,碰到了和你一样的方法,你试试这种方法吧
https://blog.csdn.net/alwayssmile21/article/details/52965742 -
yangjes_yii 回复于 2016-02-29 22:49 举报
<?php $this->beginPage(); ?> // 添加 a <!DOCTYPE html> <html lang="en"> <title>Blank</title> <?php $this->head(); ?> // 添加 b </head> <body> <?php $this->beginBody(); ?> // 添加 c …… <?php $this->endBody(); ?> // 添加 d </body> </html> <?php $this->endPage(); ?> // 添加 e
37937 觉得很赞 -
来来来,往这看 yii2 如何在页面底部加载css和js
-
-
-
-
href="<? echo 'http://'.$_SERVER['HTTP_HOST'].'/web/css/index.css'?>"
-
写全居然会被屏蔽
src="<? echo 'http://'.$_SERVER['HTTP_HOST'].'/web/js/demo.js'?>" -
-
penghui
注册时间:2014-11-07
最后登录:2014-12-09
在线时长:4小时2分
最后登录:2014-12-09
在线时长:4小时2分
- 粉丝0
- 金钱35
- 威望0
- 积分75