php - 警告 : Invalid argument supplied for foreach() in Magento error log

标签 php xml magento error-handling magento-1.7

2014-02-11T11:12:15+00:00 ERR (3): Warning: Invalid argument supplied for foreach()  in /var/www/magento/app/code/local/Bintime/Sinchimport/Block/Layer/View.php on line 19
2014-02-11T11:12:17+00:00 ERR (3): Notice: Undefined variable: bgHandle  in /var/www/magento/app/code/community/Magehouse/Slider/Block/Catalog/Layer/Filter/Price.php on line 457
2014-02-11T11:12:17+00:00 ERR (3): Notice: Undefined variable: bgSlider  in /var/www/magento/app/code/community/Magehouse/Slider/Block/Catalog/Layer/Filter/Price.php on line 461
2014-02-11T11:12:17+00:00 ERR (3): Notice: Undefined variable: bgRange  in /var/www/magento/app/code/community/Magehouse/Slider/Block/Catalog/Layer/Filter/Price.php on line 465

我一直在清除旧的错误日志,这让我陷入了困境。我不知道是哪个文件导致了问题(如果有的话)。上面的 4 个错误总是在让步中弹出,所以它可能是插件/主题冲突。第一行是指以下插件:

http://bit.ly/1dfpIID

其他三个指向我认为是产品页面主题附带的价格 slider 。

链接到开发网站:http://bit.ly/1mAxK2a

该网站正在运行 Magento 1.8.1,主题为来自 themeforest 的名为 metro store。

这是 View.php:
<?php

class Bintime_Sinchimport_Block_Layer_View extends Mage_Catalog_Block_Layer_View
{

    protected $filterableFeatures = array();

    /**
     * Prepare child blocks
     *
     * @return Mage_Catalog_Block_Layer_View
     */
    protected function _prepareLayout()
    {
        //получение списка фич, по которым строися навигация
        $filterableFeatures = $this->getLayer()->getFilterableFeatures();
        $filterBlockName = 'sinchimport/layer_filter_feature'; //block
        foreach ($filterableFeatures as $feature) {
            $this->filterableFeatures[] = $feature;
            $featureBlock = $this->getLayout()->createBlock($filterBlockName)
                    ->setLayer($this->getLayer())
                    ->setAttributeModel($feature)
                    ->init();
            $this->setChild('feature_' . $feature['feature_id'] . '_filter',
                            $featureBlock
                           );
        }
/* ------------ */
        return parent::_prepareLayout();
    }

    /**
     * Get all layer filters
     *
     * @return array
     */
    public function getFilters()
    {
        $filters = parent::getFilters();
/* ------------ */     
        foreach ($this->filterableFeatures as $feature) {
            $filters[] = $this->getChild('feature_' . $feature['feature_id'] . '_filter');
        }       
/* ------------ */

        return $filters;
    }
}

这是 Price.php:

http://pastebin.com/BCyFxCe7

有谁知道这些错误是什么意思或如何解决它们?

最佳答案

这意味着您正在向 foreach 传递不是数组的东西。

您必须先验证:

if (count($array) > 0 && is_array($array)) {
   foreach ($array as $key=>$value) {
      //code here
   }
}

[编辑]
在您的代码中“foreach ($filterableFeatures as $feature)”和“foreach ($this->filterableFeatures as $feature)”没有保护。

关于php - 警告 : Invalid argument supplied for foreach() in Magento error log,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21705942/

相关文章:

php - 使用 AJAX 将 DOM 元素值传递给 PHP

asp.net - 使用 AJAX 从 ASPX 站点检索 XML 数据

java - NullPointerException 在 textview 中使用 fragment

java - 值在模式方面不是有效的

php - 获取在 magento 中应用的税收规则的名称

php - 从电子邮件正文中删除 header

php - 在自定义查询php中匹配用户密码

php - 什么时候在 Laravel 中使用 Repository vs Service vs Trait?

php - 如何在magento中动态改变价格值

css - Magento 响应式设计 - 横向产品类别