Jump to content

Fix WARN in error log caused by search controller


DARKF3D3

Recommended Posts

 

Recently I found a lot of line like this into my server error log:

[Mon Oct 12 16:46:22 2015] [warn] [client 152.247.xxx.xxx] mod_fcgid: stderr: PHP Warning:  Invalid argument supplied for foreach() in /var/www/xxxxxx/xxxxxxx.com/xxxxxxx/controllers/front/SearchController.php on line 98, referer: http://www.website.com

This is the line 98 of the SearchController.php file:

foreach ($search['result'] as &$product) 
Any idea on how to fix this?
Link to comment
Share on other sites

  • 5 months later...
  • 6 months later...
Make sure you have the if statement wrapped around the foreach:



if (is_array($search['result'])) {
foreach ($search['result'] as &$product) {
$product['link'] .= (strpos($product['link'], '?') === false ? '?' : '&').'search_query='.urlencode($query).'&results='.(int)$search['total'];
}
}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...