我使用以下配置通过资产管理器在资产路径中添加时间戳。
'assetManager' => [
'appendTimestamp' => true,
appAsset.php
class AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
'/css/style.css'
];
}
在视图中
AppAsset::register($this);
但在html中,我仍然看到没有时间戳的'/css/style.css'
。
我看到了solution https://github.com/yiisoft/yii2/issues/9101#issuecomment-267274327
$file = '/css/style.css';
$asset = new \yii\web\AssetBundle(
[
'js' => [ltrim($file, '/')],
'basePath' => '@webroot',
'baseUrl' => '/'
]
);
$this->getAssetManager()->bundles[$file] = $asset;
$this->registerAssetBundle($file);
这个例子就是工作。'/css/style.css?v=12557565'
有没有不在视图文件中写registerAssetBundle()的方法?
发布于 2018-09-20 06:20:10
尝试编写不带斜杠的public $css
和public $js
("js/..“而是"/js/..")。
https://stackoverflow.com/questions/48236122
复制相似问题