Skip to content

Instantly share code, notes, and snippets.

@magevision
Last active May 20, 2019 11:55
Show Gist options
  • Save magevision/07952f440c0f914e29b92e957caa67f2 to your computer and use it in GitHub Desktop.
Save magevision/07952f440c0f914e29b92e957caa67f2 to your computer and use it in GitHub Desktop.
AddACustomSession
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<virtualType name="MageVision\Blog43\Model\Session\Storage" type="Magento\Framework\Session\Storage">
<arguments>
<argument name="namespace" xsi:type="string">blog43</argument>
</arguments>
</virtualType>
<type name="MageVision\Blog43\Model\Session">
<arguments>
<argument name="storage" xsi:type="object">MageVision\Blog43\Model\Session\Storage</argument>
</arguments>
</type>
</config>
<?php
namespace MageVision\Blog43\Model;
use Magento\Framework\Session\SessionManager;
/**
* Blog43 session model
*/
class Session extends SessionManager
{
}
<?php
namespace MageVision\Blog43\Block;
use Magento\Framework\View\Element\Template;
use MageVision\Blog43\Model\Session;
class TestBlockClass extends Template
{
/**
* @var Session
*/
protected $session;
/**
* @param Session $productOptionFactory
*/
public function __construct(
Session $session
) {
$this->session = Session;
}
public function sessionData()
{
$this->session->setData('custom', 'value');
$this->session->getData('custom');
$this->session->unsetData('custom');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment