prestashop_newuser Posted February 26, 2015 Share Posted February 26, 2015 Hi, I am developing a module in Prestashop 1.6.X . In this module I am setting a custom cookie using js. Now in the module php file I am checking if the cookie is set then do something. So for that I am doing this code if (isset( $_COOKIE['mycookie'] )) { echo 'hello'; } Here mycookie is the cookie name that I have made set using js.Its working fine. But when I am trying to validate the module its showing error. It is showing error like The use of $_COOKIE is forbidden; use Context::getContext()->cookie instead . So can someone tell me how to check the cookie name by using Context::getContext()->cookie. I have tried Context::getContext()->cookie('mycookie') .But its not working. Any help and suggestions will be really appreciable. Thanks Link to comment Share on other sites More sharing options...
roo10 Posted December 9, 2016 Share Posted December 9, 2016 I'm also stuck on this topic. I have tried the below code but didn't work. Context::getContext()->cookie->mycookie; Any help on this topic is much appreciated. Link to comment Share on other sites More sharing options...
rocky Posted December 11, 2016 Share Posted December 11, 2016 Try the following: Context::getContext()->cookie->exists(); Link to comment Share on other sites More sharing options...
roo10 Posted December 11, 2016 Share Posted December 11, 2016 (edited) Does that code check if cookie exists or not? If yes, then its not the solution I'm looking for. My question is very well explained in first post of this topic. Below is my code in JS file. $('.apply').click(function() { $.cookie('MyName', 'John'); }); Currently, I use below code in PHP file. if ( isset($_COOKIE['MyName']) ) { $_COOKIE['MyName']; } It works perfect but using $_COOKIE shows error while validating the module. So, how to get this cookie in module's PHP file? Edited December 11, 2016 by roo10 (see edit history) Link to comment Share on other sites More sharing options...
rocky Posted December 11, 2016 Share Posted December 11, 2016 Sorry, I thought you were just trying to check whether the PrestaShop cookie exists using the Cookie class. It's impossible to use the Cookie class to load a custom cookie. You should consider adding your custom variables to PrestaShop's cookie instead of a separate cookie. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now