Magento 2 – How to Unserialize Backend Config?

datajsonmagento2unserialize

I've created Magento 2 module that saves a particular configuration. Screenshot:enter image description here

Now I want to use this value in a frontend block. If I check the core_config table, the value is saved like this:

a:1:{s:18:"_1498478770604_604";a:4:{s:4:"name";s:12:"Number Pi";s:5:"image";s:23:"/media/wysiwyg/test.png";s:4:"text";s:606:"Lorum ipsum";s:20:"activation_attribute";s:1:"1";}}

How can I decode or unserialize this data? I want to turn this data into a (object) array that I can use on the frontend.

I've used the PHP function unserialize() but this didn't work. Also i've searched the Magento 2 JSON decode library, but I didn't find an answer there.

Any help would be appreciated.

Best Answer

Use \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, In your constructor argument and set the class property: $this->scopeConfig = $scopeConfig;

Now to Get the configuration value just use

$fields =  $this->scopeConfig->getValue('yourSystemConfigPath', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
$fields = unserialize($fields);