Yii2 assets注册的css样式文件没有加载
2016-11-08 22:30
218 查看
准备引入layui.css文件的,在LayuiAssets类中已经配置了资源属性
但是,打开网页没有引入,发现目录下已经发布了css样式文件,原来yii2 在加载css 的资源文件时,会注册时会生成对应的link标签,但是还未加入网页中,引入文件是通过layout中生成一个占位符常量,例如
然后通过strtr函数对占位符进行替换,换成对应的的代码:
renderHeadHtml这个方法时在页面结束的时候进行占位符替换,将头部占位符换成成对应注册的css和js代码。如下是生成link标签的函数
但是并没有引入,如果需要引入,需要生成占位符即可,所以之前的css未引入的问题,只要在layout的头部添加一个<?= $this -> head() ?>就好了。
<?php namespace frontend\assets; use yii\web\AssetBundle; class LayuiAsset extends AssetBundle { public $sourcePath = "@frontend/assets/app"; public $js = [ 'layer.js', 'layui.js', ]; public $css = [ 'css/layui.css' ]; public $jsOptions = ['position' => \yii\web\view::POS_HEAD]; public $depends = [ 'yii\web\JqueryAsset', ]; }
但是,打开网页没有引入,发现目录下已经发布了css样式文件,原来yii2 在加载css 的资源文件时,会注册时会生成对应的link标签,但是还未加入网页中,引入文件是通过layout中生成一个占位符常量,例如
const PH_HEAD = '<![CDATA[YII-BLOCK-HEAD]]>';
然后通过strtr函数对占位符进行替换,换成对应的的代码:
public function endPage($ajaxMode = false) { $this->trigger(self::EVENT_END_PAGE); $content = ob_get_clean(); echo strtr($content, [ self::PH_HEAD => $this->renderHeadHtml(), self::PH_BODY_BEGIN => $this->renderBodyBeginHtml(), self::PH_BODY_END => $this->renderBodyEndHtml($ajaxMode), ]); $this->clear(); }
renderHeadHtml这个方法时在页面结束的时候进行占位符替换,将头部占位符换成成对应注册的css和js代码。如下是生成link标签的函数
/** * Renders the content to be inserted in the head section. * The content is rendered using the registered meta tags, link tags, CSS/JS code blocks and files. * @return string the rendered content */ protected function renderHeadHtml() { $lines = []; if (!empty($this->metaTags)) { $lines[] = implode("\n", $this->metaTags); } if (!empty($this->linkTags)) { $lines[] = implode("\n", $this->linkTags); } if (!empty($this->cssFiles)) { $lines[] = implode("\n", $this->cssFiles); } if (!empty($this->css)) { $lines[] = implode("\n", $this->css); } if (!empty($this->jsFiles[self::POS_HEAD])) { $lines[] = implode("\n", $this->jsFiles[self::POS_HEAD]); } if (!empty($this->js[self::POS_HEAD])) { $lines[] = Html::script(implode("\n", $this->js[self::POS_HEAD]), ['type' => 'text/javascript']); } return empty($lines) ? '' : implode("\n", $lines); }
但是并没有引入,如果需要引入,需要生成占位符即可,所以之前的css未引入的问题,只要在layout的头部添加一个<?= $this -> head() ?>就好了。
相关文章推荐
- “RegSvr32 已加载mshtml.dll,但没有找到DllRegisterServer输入点。无法注册这个文件。”解决办法全集
- 已加载dcrf32.dll,但没有找到DllRegisterServer输入点。无法注册这个文件
- 完美解决IIS服务器无法加载应用程序 '/LM/W3SVC/1/ROOT'-没有注册类别的问题
- 解决CD12"未能创建DOM文件,没有注册类别,校验MSXML4安装&
- 关于ubuntu的“没有为此类型文件注册相应的处理程序”
- 用LazyLoad实现Javascript脚本与Css样式文件延迟加载
- VS 2010无法创建项目提示写入项目文件时出错 没有注册类别
- IE浏览器没有加载CSS文件的秘密
- vs2010 "写入项目文件时出错。没有注册类别","无法读取项目文件",解决方法
- IIS HTTP 500 - 内部服务器错误完美解决 IIS 服务器无法加载应用程序 '/LM/W3SVC/1/ROOT'。错误是 '没有注册类别
- 未能加载文件或程序集“XXXXX”或它的某一个依赖项。未能验证强名称签名。此程序集可能已被篡改,或者已被延迟签名,但没有用正确的私钥进行完全签名。 (异常来自 HRESULT:0x80131045)
- 媒体播放器播放音频或视频文件提示“没有注册类别”情况的解决办法。
- 完美解决IIS 服务器无法加载应用程序 '/LM/W3SVC/1/ROOT'。错误是 '没有注册类别
- 您的用户配置文件没有正确加载
- 解决vs2010 新建项目报错:写入项目文件时出错 没有注册类别
- 完美解决IIS服务器无法加载应用程序 '/LM/W3SVC/1/ROOT'-没有注册类别
- wcf .svc文件在vista上没有为之注册mime 映射
- 加载spring信息,属性文件信息,注册proxool
- C++中类型注册有的时候,函数找不到定义,可能是相应的头文件中防止重定义的声明,还是用原来的,没有做相应的更新
- 安装后运行CorelDRAW12 错误提示“未能创建DOM文件 没有注册类别 请校验MSXML4的安装”的解决方法