Jump to content

Globals are deprecated, please use the Context instead


Recommended Posts

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

  • 2 months later...

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 by prestashop_newuser (see edit history)
Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

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

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

  • 2 years later...

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

×
×
  • Create New...