错误过滤模板:注意:unserialize()

时间:2017-10-18 08:57:09

标签: php magento2

我有这个样本:

代码PHP:

["conditions_encoded"] => string(324) "a:2:[i:1;a:4:[s:4:`type`;s:50:`Magento|CatalogWidget|Model|Rule|Condition|Combine`;s:10:`aggregator`;s:3:`all`;s:5:`value`;s:1:`1`;s:9:`new_child`;s:0:``;]s:4:`1--1`;a:4:[s:4:`type`;s:50:`Magento|CatalogWidget|Model|Rule|Condition|Product`;s:9:`attribute`;s:12:`category_ids`;s:8:`operator`;s:2:`==`;s:5:`value`;s:3:`140`;]]"

我尝试使用此代码反序列化:

<?php Zend_Debug::dump(base64_decode(unserialize($block->getConditionsEncoded())));?>

但是我收到了这个错误:

Error filtering template: Notice: unserialize(): Error at offset 0 of 324 bytes 

如何修复此错误?您认为哪种解决方案。

提前致谢!

1 个答案:

答案 0 :(得分:0)

问题是,这不是使用php serialize序列化的数据。至  解码存储在conditions_encoded中的数据,你可以使用\Magento\Widget\Helper\Conditions助手,它有一个解码方法。

我再次查看了您的序列化数据,看起来,它并不完全是格式,magento存储在widget_encoded var中,用于小部件。但看起来,您的代码使用了{ => [} => ]`` => "的简单替换,因此您可以使用以下内容轻松恢复它:

$unescaped = str_replace(
    ['[', ']', '`'],
    ['{', '}', '"'],
    $encoded);

$data = unserialize($unescaped);