tamir
tamir

Reputation: 3297

create global non-cached variable

How can i create a global variable in Symfony, but one that will never be cached?

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!

Upvotes: 1

Views: 608

Answers (1)

P. R. Ribeiro
P. R. Ribeiro

Reputation: 3029

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();

Upvotes: 3

Related Questions