0

I am using it in my code to get the cookie in a simple PHP way. But need to get in Magento 2 standard format.

Here is my code:

if(isset($_COOKIE['getCookie'])){
     .................
}

How to get in Magento standard format?

Thanks

2

You need to use in a php file the cookieManager

protected $_cookieManager;

public function __construct(
    \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager
)
{
    $this->_cookieManager = $cookieManager;
}

You can get the cookie with :

$cookieValue = $this->_cookieManager->getCookie("CookieName");

You can delete a cookie with :

$this->_cookieManager->deleteCookie(
                "CookieName"
            );
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.