nil2567 Posted December 7, 2013 Share Posted December 7, 2013 Hello, I'm trying to pass a variable to tpl trought global $smarty inside my function but prestashop validator tell's me: Please check your submission at validator.prestashop.com and remove errors Globals are deprecated How can I do that? Thanks Link to comment Share on other sites More sharing options...
vekia Posted December 7, 2013 Share Posted December 7, 2013 hello instead of global $smarty; use $this->smarty Link to comment Share on other sites More sharing options...
prestashop_newuser Posted February 13, 2014 Share Posted February 13, 2014 hello instead of global $smarty; use $this->smarty hi, I want to know how to use global variable for $cookie. global $cookie; How this can be declared? Link to comment Share on other sites More sharing options...
El Patron Posted February 13, 2014 Share Posted February 13, 2014 this document may help http://doc.prestashop.com/display/PS15/Using+the+Context+Object Link to comment Share on other sites More sharing options...
prestashop_newuser Posted February 13, 2014 Share Posted February 13, 2014 this document may help http://doc.prestashop.com/display/PS15/Using+the+Context+Object $this->context->cookie = $cookie will help for global $cookie? Link to comment Share on other sites More sharing options...
El Patron Posted February 13, 2014 Share Posted February 13, 2014 $this->context->cookie = $cookie will help for global $cookie? yes, that is correct. You can search your installation modules folder to see how native prestashop uses context. Then you can learn/copy that code. Link to comment Share on other sites More sharing options...
prestashop_newuser Posted February 14, 2014 Share Posted February 14, 2014 yes, that is correct. You can search your installation modules folder to see how native prestashop uses context. Then you can learn/copy that code. Yes. But when I am using $this->context->cookie = $cookie; it is showing error like Undefined variable: cookie? Link to comment Share on other sites More sharing options...
vekia Posted February 14, 2014 Share Posted February 14, 2014 hello i've noticed that you created another topic related to this. so i decided to copy message here can you show the code where you're trying to use $this->context->cookie and $this->smarty Link to comment Share on other sites More sharing options...
prestashop_newuser Posted February 14, 2014 Share Posted February 14, 2014 (edited) hello i've noticed that you created another topic related to this. so i decided to copy message here Yes. I have used both global variables inside displayForm() function and the smarty variable in hookdisplayTop($params) function like this public function displayForm() { $this->context->cookie = $cookie; $this->_html .= ' '; } public function hookdisplayTop($params) { $this->smarty; $result = "SELECT * FROM "._DB_PREFIX_."databasename where status='1'"; $value = Db::getInstance()->ExecuteS($result); $smarty->assign('values',$value); return $this->display(__FILE__, 'views/templates/display.tpl'); } So can you tell me how to solve this issue? Note: prior this I had used global variables for both Cookie and Smarty. Edited February 14, 2014 by prestashop_newuser (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted February 14, 2014 Share Posted February 14, 2014 you still use $cookie variable. don't use it anymore, just simple $this->context->cookie the same with $this->smarty; for what purposes you use this code? you don't have to define it in that way, because smarty object in $this is already defined, the same context & cookie also you still use $smarty variable $smarty->assign('values',$value); don't use it anymore use $this->smarty instead $smarty 1 Link to comment Share on other sites More sharing options...
prestashop_newuser Posted February 14, 2014 Share Posted February 14, 2014 you still use $cookie variable. don't use it anymore, just simple the same with $this->smarty; for what purposes you use this code? you don't have to define it in that way, because smarty object in $this is already defined, the same context & cookie also you still use $smarty variable don't use it anymore use $this->smarty instead $smarty That means there is no need to assign smarty variable? Only $this->smarty('values',$value); will work? Link to comment Share on other sites More sharing options...
NemoPS Posted February 14, 2014 Share Posted February 14, 2014 That means there is no need to assign smarty variable? Only $this->smarty('values',$value); will work? WHat do you meant? Declaring the global? No, it's not necessary anymore, you should however use it as $this->context->smarty->assign.... Link to comment Share on other sites More sharing options...
Kerm Posted April 30, 2016 Share Posted April 30, 2016 What if in module you include php file with some class in public function __construct() section, and after in this class class Functions extends ObjectModel{} you want recive cookie object data? If you use this: $this->context->cookie you get error like that: Creating default object from empty value and how get cookie data with out using global in module class? PS: I found this code, tell me, is that right code for get current backoffice user cookies? $cookie = new Cookie('psAdmin', '', (int)Configuration::get('PS_COOKIE_LIFETIME_BO')); Link to comment Share on other sites More sharing options...
vekia Posted May 2, 2016 Share Posted May 2, 2016 if you will put it after parent::init(); it should work Link to comment Share on other sites More sharing options...
Kerm Posted May 10, 2016 Share Posted May 10, 2016 if you will put it after parent::init(); it should work I don't understand, put what? Include php files after parent::init()? Link to comment Share on other sites More sharing options...
vekia Posted May 10, 2016 Share Posted May 10, 2016 this code: $cookie = new Cookie('psAdmin', '', (int)Configuration::get('PS_COOKIE_LIFETIME_BO')); will work, if you will put it after parent::intit(); inside function __construct() Link to comment Share on other sites More sharing options...
Recommended Posts