未定义的偏移量1在使用“;Business Connect;主题与drupal7


Undefined offset 1 errors on using "Business Connect" theme with drupal 7

我在drupal 7.10中安装了"Business Connect"主题,这个主题运行良好,但有时我会收到这些错误消息。如果我安装了另一个主题,那么没有显示错误消息,这意味着问题出在"Business Connect"主题的template.php文件上。

错误消息:

Notice: Undefined offset: 1 in businessconnect_process_page() (line 44 of 
C:'xampp'htdocs'my-site-name'sites'all'themes'businessconnect'template.php).
Notice: Undefined offset: 2 in businessconnect_process_page() (line 44 of 
C:'xampp'htdocs'my-site-name'sites'all'themes'businessconnect'template.php).
Notice: Undefined offset: 3 in businessconnect_process_page() (line 44 of 
'C:'xampp'htdocs'my-site-name'sites'all'themes'businessconnect'template.php).

Template.php代码:

if ($variables['is_front'])
{
    $variable=$variables['title'];
    $text=(explode(" ", $variable));
    $variables['title'] = '<span>'.$text[0].' '.$text[1].' '.'<span class="title_default">'.$text[2].' '.$text[3].'</span>'.'</span>';
}

第44行:

    $variables['title'] = '<span>'.$text[0].' '.$text[1].' '.'<span class="title_default">'.$text[2].' '.$text[3].'</span>'.'</span>';

冒着@hakre生我气的风险…:)

错误消息是业务连接脚本引用实际不存在的变量($text[1]、$text[2]、$text[3])的结果。您可以通过将第44行替换为以下内容来纠正问题:

for ($i=0;$i<4;$i++) {
  $var = "mytext$i";
  $$var = isset($text[$i]) ? $text[$i] : '';
}
$variables['title'] = '<span>'.$mytext0.' '.$mytext1.' <span class="title_default">'.$mytext2.' '.$mytext3.'</span></span>';

破解第三方脚本的内部通常不是一个好主意。。。但在这种情况下,创作这个主题的经验不足的人不太可能很快纠正这个问题。