两个"数组到字符串转换"通知(Prestashop)

时间:2016-10-06 06:14:00

标签: php arrays string prestashop notice

我不确定在一个问题中发布这两个问题是否明智,但试试看:

所以,我正在检查我的服务器的错误日志,它仍然有两个注意事项,关于"数组到#34;中的字符串转换。

第一行应该是:

 $replace = $route['keywords'][$key]['prepend'].$params[$key].$route['keywords'][$key]['append'];

上下文:

        // Build an url which match a route
    if ($this->use_routes || $force_routes) {
        $url = $route['rule'];
        $add_param = array();

        foreach ($params as $key => $value) {
            if (!isset($route['keywords'][$key])) {
                if (!isset($this->default_routes[$route_id]['keywords'][$key])) {
                    $add_param[$key] = $value;
                }
            } else {
                if ($params[$key]) {
                    $replace = $route['keywords'][$key]['prepend'].$params[$key].$route['keywords'][$key]['append'];
                } else {
                    $replace = '';
                }
                $url = preg_replace('#\{([^{}]*:)?'.$key.'(:[^{}]*)?\}#', $replace, $url);
            }
        }
        $url = preg_replace('#\{([^{}]*:)?[a-z0-9_]+?(:[^{}]*)?\}#', '', $url);
        if (count($add_param)) {
            $url .= '?'.http_build_query($add_param, '', '&');
        }
    }

第二个是这一行:

                $uri_path = __PS_BASE_URI__.$id_image.($type ? '-'.$type : '').$theme.'/'.$name.'.jpg';

作为其中的一部分:

        // legacy mode or default image
    $theme = ((Shop::isFeatureActive() && file_exists(_PS_PROD_IMG_DIR_.$ids.($type ? '-'.$type : '').'-'.(int)Context::getContext()->shop->id_theme.'.jpg')) ? '-'.Context::getContext()->shop->id_theme : '');
    if ((Configuration::get('PS_LEGACY_IMAGES')
        && (file_exists(_PS_PROD_IMG_DIR_.$ids.($type ? '-'.$type : '').$theme.'.jpg')))
        || ($not_default = strpos($ids, 'default') !== false)) {
        if ($this->allow == 1 && !$not_default) {
            $uri_path = __PS_BASE_URI__.$ids.($type ? '-'.$type : '').$theme.'/'.$name.'.jpg';
        } else {
            $uri_path = _THEME_PROD_DIR_.$ids.($type ? '-'.$type : '').$theme.'.jpg';
        }
    } else {
        // if ids if of the form id_product-id_image, we want to extract the id_image part
        $split_ids = explode('-', $ids);
        $id_image = (isset($split_ids[1]) ? $split_ids[1] : $split_ids[0]);
        $theme = ((Shop::isFeatureActive() && file_exists(_PS_PROD_IMG_DIR_.Image::getImgFolderStatic($id_image).$id_image.($type ? '-'.$type : '').'-'.(int)Context::getContext()->shop->id_theme.'.jpg')) ? '-'.Context::getContext()->shop->id_theme : '');
        if ($this->allow == 1) {
            $uri_path = __PS_BASE_URI__.$id_image.($type ? '-'.$type : '').$theme.'/'.$name.'.jpg';
        } else {
            $uri_path = _THEME_PROD_DIR_.Image::getImgFolderStatic($id_image).$id_image.($type ? '-'.$type : '').$theme.'.jpg';
        }
    }

    return $this->protocol_content.Tools::getMediaServer($uri_path).$uri_path;
}

public function getMediaLink($filepath)
{
    return $this->protocol_content.Tools::getMediaServer($filepath).$filepath;
}

PHP不是我的力量,所以我不知道该怎么做:/ 另外我还发现了一些关于Array的字符串通知的问题,但在我看来,你似乎无法以同样的方式解决它们......

提前感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

出现此错误是因为这两行中的某些变量应该是String,但它们实际上是数组。

您需要使用PHP的var_dump()函数打印这两行中使用的所有变量,这将告诉您哪些变量实际上是一个数组,但根据您的代码,它们应该是一个String。

根据输出,您需要修改代码以解决问题。