开发者

create global non-cached variable

开发者 https://www.devze.com 2023-03-22 23:49 出处:网络
How can i create a global variable in Symfony, but one that will never be cache开发者_如何学Pythond?

How can i create a global variable in Symfony, but one that will never be cache开发者_如何学Pythond?

I basically want to be able to get BaseForm token key anywhere in my app without the need to create a new instance of it every time..

Thanks!


You should create a static method and store the token you need in a static variable.

// /lib/form/BaseForm.class.php
protected static $token = null;

public static getToken(){
  if(is_null(self::$token)){
    $form = new BaseForm();
    self::$token = $form->getCSRFToken();
  }
  return self::$token;
}

public static setToken($){
  self::$token = 
}

You use it then

BaseForm::getToken();
0

精彩评论

暂无评论...
验证码 换一张
取 消