I'm getting the error "2: Invalid argument supplied for foreach()" in my index.template.php where the buttons are made..... (literally the "foreach line")
// Generate a strip of buttons.
function template_button_strip($button_strip, $direction = 'top', $strip_options = array())
{
global $settings, $context, $txt, $scripturl;
if (!is_array($strip_options))
$strip_options = array();
// Create the buttons...
$buttons = array();
foreach ($button_strip as $key => $value)
{
if (!isset($value['test']) || !empty($context[$value['test']]))
$buttons[] = '
<li><a' . (isset($value['id']) ? ' id="button_strip_' . $value['id'] . '"' : '') . ' class="button_strip_' . $key . (isset($value['active']) ? ' active' : '') . '" href="' . $value['url'] . '"' . (isset($value['custom']) ? ' ' . $value['custom'] : '') . '><span>' . $txt[$value['text']] . '</span></a></li>';
}
// No buttons? No button strip either.
if (empty($buttons))
return;
// Make the last one, as easy as possible.
$buttons[count($buttons) - 1] = str_replace('<span>', '<span class="last">', $buttons[count($buttons) - 1]);
echo '
<div class="buttonlist', !empty($direction) ? ' float' . $direction : '', '"', (empty($buttons) ? ' style="display: none;"' : ''), (!empty($strip_options['id']) ? ' id="' . $strip_options['id'] . '"': ''), '>
<ul>',
implode('', $buttons), '
</ul>
</div>';
}
I don't really understand the code...can anyone else figure out what's up? :)
Well, that function is called in a bunch of places, so the error depends on the value being passed when the function is called...
That's the same code from default theme (except for RTL) so I'd suggest you to add
echo '<pre>';
print_r ($button_strip);
echo '</pre>';
Somewhere in the beginning of the function. And check the results. One of the calls will probably not have an array... When you know which is it, you can then proceed to understand why :P
Every single one of them has an array :(.
Can you paste the "print_r" result?
Not sure how that will help but sure.
Message index:
Array
(
[new_topic] => Array
(
[test] => can_post_new
[text] => new_topic
[image] => new_topic.gif
[lang] => 1
[url] => http://www.creativeburrow.org/index.php?action=post;board=2.0
[active] => 1
)
[post_poll] => Array
(
[test] => can_post_poll
[text] => new_poll
[image] => new_poll.gif
[lang] => 1
[url] => http://www.creativeburrow.org/index.php?action=post;board=2.0;poll
)
[notify] => Array
(
[test] => can_mark_notify
[text] => notify
[image] => notify.gif
[lang] => 1
[custom] => onclick="return confirm('Are you sure you wish to enable notification of new topics for this board?');"
[url] => [removed]
)
[markread] => Array
(
[text] => mark_read_short
[image] => markread.gif
[lang] => 1
[url] => [removed]
)
)
Array
(
[new_topic] => Array
(
[test] => can_post_new
[text] => new_topic
[image] => new_topic.gif
[lang] => 1
[url] => http://www.creativeburrow.org/index.php?action=post;board=2.0
[active] => 1
)
[post_poll] => Array
(
[test] => can_post_poll
[text] => new_poll
[image] => new_poll.gif
[lang] => 1
[url] => http://www.creativeburrow.org/index.php?action=post;board=2.0;poll
)
[notify] => Array
(
[test] => can_mark_notify
[text] => notify
[image] => notify.gif
[lang] => 1
[custom] => onclick="return confirm('Are you sure you wish to enable notification of new topics for this board?');"
[url] => [removed]
)
[markread] => Array
(
[text] => mark_read_short
[image] => markread.gif
[lang] => 1
[url] => [removed]
)
)
Personal Messages:
Array
(
[reply] => Array
(
[text] => reply_to_all
[image] => reply.gif
[lang] => 1
[url] => http://www.creativeburrow.org/index.php?action=pm;sa=send;f=inbox;pmsg=2418;u=all
[active] => 1
)
[mark_unread] => Array
(
[text] => mark_unread_all
[image] => mark_unread.gif
[lang] => 1
[url] => [removed]
)
[delete] => Array
(
[text] => delete_conversation
[image] => delete.gif
[lang] => 1
[url] => [removed]
[custom] => onclick="return confirm('Remove this message?');"
)
)
I can't seem to trigger it again but it was filling up my logs for months so I'm not sure what to make of the sudden disappearance?
Well, that seems OK. So if it's not happening again, we have to assume that some button was wrongly coded...
If it happens again, print_r it ;)
Thank you :)