Reputation: 3297
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
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