无法使用 cakePHP html 助手添加 css 版本控制
cannot add css versioning with cakePHP html helper
我想在我的 css 文件中添加一个版本号,但我没有找到使用 html 帮助程序来完成此操作的方法。
我看到一个通过 bootstrap.php 添加时间戳的示例,但我希望能够自己控制版本号。
我正在使用 cakephp 2.3
style.min.css?v=1
<?php
echo $this->Html->css('style.min', array('v'=>'1'));
echo $this->fetch('css');
?>
或
<?php
echo $this->Html->css('style.min?v=1');
echo $this->fetch('css');
?>
只需添加 .css
echo $this->Html->css('style.min.css?v=1');
虽然省略 .css
是标准做法,但包含它是可以接受的,并且允许您在 URL.
的末尾添加额外的参数
在 CakePHP 3x 中,您可以在 config/app.php
中执行此操作。
/**
* Apply timestamps with the last modified time to static assets (js, css, images).
* Will append a querystring parameter containing the time the file was modified.
* This is useful for busting browser caches.
*
* Set to true to apply timestamps when debug is true. Set to 'force' to always
* enable timestamping regardless of debug value.
*/
'Asset' => [
// 'timestamp' => true,
],
我想在我的 css 文件中添加一个版本号,但我没有找到使用 html 帮助程序来完成此操作的方法。
我看到一个通过 bootstrap.php 添加时间戳的示例,但我希望能够自己控制版本号。
我正在使用 cakephp 2.3
style.min.css?v=1
<?php
echo $this->Html->css('style.min', array('v'=>'1'));
echo $this->fetch('css');
?>
或
<?php
echo $this->Html->css('style.min?v=1');
echo $this->fetch('css');
?>
只需添加 .css
echo $this->Html->css('style.min.css?v=1');
虽然省略 .css
是标准做法,但包含它是可以接受的,并且允许您在 URL.
在 CakePHP 3x 中,您可以在 config/app.php
中执行此操作。
/**
* Apply timestamps with the last modified time to static assets (js, css, images).
* Will append a querystring parameter containing the time the file was modified.
* This is useful for busting browser caches.
*
* Set to true to apply timestamps when debug is true. Set to 'force' to always
* enable timestamping regardless of debug value.
*/
'Asset' => [
// 'timestamp' => true,
],