一个朋友正在建设的Drupal网站,Views的管理界面访问不了了。一直解决不了,周末我帮着调试,检查原因。
首先,是备份数据,将现在的数据备份一下。
我尝试,将现有的模块,特别是第3方模块禁用,从而避免模块冲突的可能。第三方模块全部禁用后,还是无法访问。
我接着尝试将Views相关的数据,从数据库表中完全清空,包括对应的缓存。还是不行。
我又尝试将views的版本升级到最新的稳定版本,还是无法访问。
我将Views完全卸载,然后重新安装。还是无法访问。
尝试Views管理界面的其它页面,比如admin/structure/views/add,页面也是空白的,更多的路径都尝试了一遍,全是无法访问,整个页面都停在了那里,没有任何反应,最主要的是没有任何错误输出。
没有任何错误提示,这是最让人头疼的。
没有特别好的办法,我就尝试分析对应的源代码了,首先找到admin/structure/views/add对应的回调函数views_ui_add_page;
function views_ui_add_page() {
views_ui_add_admin_css();
drupal_set_title(t('Add new view'));
//return '123456';
return drupal_get_form('views_ui_add_form');
}
我将这里面的代码全部注释掉,换成return '123456';
现在访问这个页面,显示出来了123456。接着我对这几行代码进行逐个的排查,原来是views_ui_add_admin_css出了问题,将对应的代码注释掉,就可以工作。
function views_ui_add_admin_css() {
foreach (views_ui_get_admin_css() as $file => $options) {
drupal_add_css($file, $options);
}
}
通过进一步的分析,原来是(views_ui_get_admin_css这个函数里面除了问题。将里面的这段代码注释掉,就可以正常访问:
// Add in any theme specific CSS files we have
$themes = list_themes();
$theme_key = $GLOBALS['theme'];
// print debug($themes);
while ($theme_key) {
// Try to find the admin css file for non-core themes.
if (!in_array($theme_key, array('garland', 'seven', 'bartik'))) {
$theme_path = drupal_get_path('theme', $theme_key);
// First search in the css directory, then in the root folder of the theme.
if (file_exists($theme_path . "/css/views-admin.$theme_key.css")) {
$list[$theme_path . "/css/views-admin.$theme_key.css"] = array(
'group' => CSS_THEME,
);
}
else if (file_exists($theme_path . "/views-admin.$theme_key.css")) {
$list[$theme_path . "/views-admin.$theme_key.css"] = array(
'group' => CSS_THEME,
);
}
}
else {
$list[$module_path . "/css/views-admin.$theme_key.css"] = array(
'group' => CSS_THEME,
);
}
$theme_key = isset($themes[$theme_key]->base_theme) ? $themes[$theme_key]->base_theme : '';
}
我尝试禁用朋友自定义的主题,将注释取消,Views仍然能够正常工作。启用了对应的主题,就进不去了。
通过分析代码,将:
$theme_key = isset($themes[$theme_key]->base_theme) ? $themes[$theme_key]->base_theme : '';
替换为:
$theme_key = '';
启用朋友自定义的主题以后也可以工作了,我通过print debug($themes);
分析对应的输出,我发现,自定义的主题机读名字为hunan,该主题的base theme也是hunan,这导致了上面的代码进入了死循环。
我检查朋友主题的hunan.info文件,里面有这样的一段代码:
base theme = hunan
将它修改为:
base theme = zen
一切都正常了。
主题info文件里面的一个很小的错误,导致整个Views后台的界面无法访问,这两者之间看起来没有什么联系。
主题的基主题,千万不要设置为自己本身了。