Uutiset:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu
Advertisement:

2: Invalid argument supplied for foreach()

Aloittaja Jade Elizabeth, helmikuu 22, 2014, 04:23:44 AP

« edellinen - seuraava »

Jade Elizabeth

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? :)
Once proud Documentation Writer and Help Squad Leader | Check out my new adult coloring career: Color With Jade/Patreon.

margarett

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
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

LainaaOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Jade Elizabeth

Once proud Documentation Writer and Help Squad Leader | Check out my new adult coloring career: Color With Jade/Patreon.

margarett

Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

LainaaOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Jade Elizabeth

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?
Once proud Documentation Writer and Help Squad Leader | Check out my new adult coloring career: Color With Jade/Patreon.

margarett

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 ;)
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

LainaaOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Jade Elizabeth

Once proud Documentation Writer and Help Squad Leader | Check out my new adult coloring career: Color With Jade/Patreon.

Advertisement: