在 magento 2 中,如何在会话中存储观察者值

In magento 2, how to store observer value in session

示例: 我有 2 个观察者 classes。 1- category.php 2- product.php 我想将 category.php 数据存储在会话变量中,例如 $_SESSION['category']= $data;并在 product.php class 中调用该会话。

像这样:

<?php
namespace Vendor\Module\Observer;

use Magento\Framework\Event\Observer as EventObserver;
use Magento\Framework\Event\ObserverInterface;
use Magento\Checkout\Model\Session as CheckoutSession;

class MyOberver implements ObserverInterface
{

protected $checkoutSession;

public function __construct(
   CheckoutSession $checkoutSession
    ) {
       $this->_checkoutSession = $checkoutSession;
    }


/**
* @param EventObserver $observer
* @return $this
*/
public function execute(EventObserver $observer)
{

   $setValue = $this->_checkoutSession->setVar('dit is een sessie test hoppa');
   $getValue = $this->_checkoutSession->getVar();

   return $this;


 }    
}