Php 两个“;“数组到字符串的转换”;通知(预售)
我不太确定在一个问题中发布这两个问题是否明智,但让我们试试: 所以,我检查了服务器的错误日志,它仍然有两个通知,都是关于“数组到字符串在[…]中的转换” 第一行应该是:Php 两个“;“数组到字符串的转换”;通知(预售),php,arrays,string,prestashop,notice,Php,Arrays,String,Prestashop,Notice,我不太确定在一个问题中发布这两个问题是否明智,但让我们试试: 所以,我检查了服务器的错误日志,它仍然有两个通知,都是关于“数组到字符串在[…]中的转换” 第一行应该是: $replace = $route['keywords'][$key]['prepend'].$params[$key].$route['keywords'][$key]['append']; 背景: // Build an url which match a route if ($this->
$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不是我的强项,所以我不知道该怎么做:/
我还发现了一些关于数组到字符串通知的其他问题,但在我看来,你不能用同样的方法解决它们
提前感谢您的帮助 出现此错误是因为这两行中的一些变量应该是字符串,但实际上是数组 您需要使用PHP的var_dump()函数打印这两行中使用的所有变量,这将告诉您哪些变量实际上是数组,但根据您的代码,它们应该是字符串
根据输出,您需要修改代码以解决问题。检查方式
print($route['keywords'][$key]['prepend']);打印($params[$key].$route['keywords'][$key]['append'])
它们打印的内容。数组还是字符串?第二个也一样,然后你可以根据你的要求调整你的代码,但是…我如何测试这个呢我不知道prestashop,但是在那行代码之前(第一行),如果你写了上面的代码,那么可能会在页面上或者你看到输出的某个地方。我想第一行应该创建一个友好的URL,比如:…/de/import/7688-keramik-schiffschale-percy.htmlSounds很好,但是我仍然要问:我该怎么做?我用这段代码创建了一个新文件,添加了var_dump($uri_path),但似乎不起作用。对不起,我对php:D还是很陌生