12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- namespace backend\assets;
- use yii\web\AssetBundle;
- use Yii;
- use yii\helpers\ArrayHelper;
- /**
- * Main backend application asset bundle.
- */
- class AppAsset extends AssetBundle
- {
- private $cacheFiles;
- public $basePath = '@webroot';
- public $baseUrl = '@web';
- public $css = [
- // 'css/site.css',
- 'static/css/index.css',
- 'static/css/public.css',
- 'static/layui_2.5/layui/css/layui.css',
- ];
- public $js = [
- 'static/layui/csrftoken.js',
- 'static/layui_2.5/layui/layui.js',
- 'static/js/ajaxRequest.js',
- // 'static/js/index.js',
- 'static/js/cache.js',
- // 'static/js/main.js',
- ];
- public $depends = [
- 'yii\web\YiiAsset',
- // 'yii\bootstrap\BootstrapAsset',
- ];
- public static function addScript($view, $jsfile) {
- $view->registerJsFile($jsfile.static::Clear(), [AppAsset::className(), "depends" => "backend\assets\AppAsset"]);
- }
- public static function addCss($view, $jsfile)
- {
- $view->registerCssFile($jsfile);
- }
- public function registerAssetFiles($view)
- {
- $manager = $view->getAssetManager();
- foreach ($this->js as $js) {
- if (is_array($js)) {
- $file = array_shift($js);
- $options = ArrayHelper::merge($this->jsOptions, $js);
- $view->registerJsFile($manager->getAssetUrl($this, $file), $options);
- } else {
- if ($js !== null) {
- $view->registerJsFile($manager->getAssetUrl($this, $js.static::Clear()), $this->jsOptions);
- }
- }
- }
- foreach ($this->css as $css) {
- if (is_array($css)) {
- $file = array_shift($css);
- $options = ArrayHelper::merge($this->cssOptions, $css);
- $view->registerCssFile($manager->getAssetUrl($this, $file), $options);
- } else {
- if ($css !== null) {
- $view->registerCssFile($manager->getAssetUrl($this, $css.static::Clear()), $this->cssOptions);
- }
- }
- }
- }
- public static function Clear()
- {
- $cache = Yii::$app->cache;
- $name = Yii::$app->params['resourceCacheKey']['backend'];
- if($cache->get($name) != false)
- {
- return '?v='.$cache->get($name);
- }
- else
- {
- return '?v=31231243211';
- }
- }
- }
|