Skip to content

Unable to Unserilize the values in phtml Magento2

I have added a blockfunction in (vendormoduleBlockDealz) as

public function __construct
(
 MagentoFrameworkSerializeSerializerInterface $serializer
) {
$this->serializer = $serializer;
}

public function unSerialize($link)
{ 
return  $this->serializer->unserialize($link);
}

After that called the function in banner.phtml as

$blockData = $block->getBlockData();


<?php foreach ($blockData as $data):
    $banner = $data->getBannerSerialized();
     $bannerUnserialize = $block->unSerialize($banner);
?>

The following is the parent phtml file that i used

 <?php if ($type=='SliderBlock'): ?>
            <?= $block->getLayout()->createBlock(vendormoduleBlockDealz::class)
                ->setTemplate("vendor_module::slider.phtml")
                ->setData('design_id',$item->getId())
                ->toHtml() ?>
       <?php endif; ?>
       
     <?php if ($type=='BannerBlock'): ?>
         <?= $block->getLayout()->createBlock(vendormoduleBlockDealz::class)
         ->setTemplate("vendor_module::banner.phtml")
         ->setData('design_id',$item->getId())
         ->toHtml() ?>
     <?php endif; ?>

I have already used the
‘$block->unSerialize()’ in slider.phtml it gots correctly. but again try to use this in banner.phtml at that time i got error as Unable to unserialize value. how to fix this.