Drupal 6 在我的模块hook_init中切换主题时,我应该如何控制drupal缓存?
我已经实现了一个drupal模块,可以根据服务器时间切换两个主题。其简化代码为:Drupal 6 在我的模块hook_init中切换主题时,我应该如何控制drupal缓存?,drupal-6,themes,cache-control,Drupal 6,Themes,Cache Control,我已经实现了一个drupal模块,可以根据服务器时间切换两个主题。其简化代码为: function toggle_themes_init() { global $custom_theme; $current_theme = variable_get('theme_default', 'garland'); // Determine the daytime $hours = (int)date('H'); $new_theme = ($hours >= 8 &
function toggle_themes_init() {
global $custom_theme;
$current_theme = variable_get('theme_default', 'garland');
// Determine the daytime
$hours = (int)date('H');
$new_theme = ($hours >= 8 && $hours < 18 ? 'light_theme' : 'dark_theme');
// If the default theme differs from $new_theme
// then we want to clear the theme cache
if ($new_theme != $current_theme) {
variable_set('theme_default', $new_theme);
drupal_rebuild_theme_registry();
}
$custom_theme = $new_theme;
}
function toggle_themes_init(){
全球$custom_主题;
$current_theme=variable_get('theme_default','garland');
//确定白天
$hours=(int)日期('H');
$new_-theme=($hours>=8&$hours<18?'light_-theme':'dark_-theme');
//如果默认主题与$new\u主题不同
//然后我们要清除主题缓存
if($new\u theme!=$current\u theme){
变量集('theme\u default',$new\u theme);
drupal_重建_主题_注册表();
}
$custom\u theme=$new\u theme;
}
我不知道如何正确地清除主题缓存(一次清除站点的所有页面)
现在某些页面上的主题不会更改(使用此代码)。例如,视图模块创建的页面上的主题已更改。而静态页面的主题不是
当我禁用drupal缓存时,一切正常
请给出一个工作建议
我将为你的帮助而高兴 尝试使用
它应该清除所有缓存并使主题更改可见
从Drupal api文档页面:
cache\u clear\u all($cid=NULL,$table=NULL,$wildcard=FALSE)
参数
$cid如果已设置,则为要删除的缓存ID。
否则,所有可以
过期的文件将被删除
$table如果设置,表$table将
从中删除。强制参数如果
$cid已设置
$wildcard如果$wildcard为TRUE,则缓存
以$cid开头的ID将在中删除
添加到确切的缓存ID
由$cid指定。如果$wildcard是
如果$cid为“*”,则整个
表$table已清空
您可以使用并指定参数来仅删除某些缓存id,而不是删除所有可过期的缓存项。您不知道,有没有更激进的方法?@artyom.stv我在回答中添加了
cache\u clear\u all()
的详细信息,有关任何其他详细信息,请参阅api文档页面。如果愿意,您可以使用cache\u clear\u all()
仅删除特定的缓存id。