Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting and Accessing Global variables

I need to have a set of Global Variables in a class, and need to access it from other classes. I have the following problems, can someone help me ?

1.) What type of class should i add ? is it a View ? Can someone show an example ? 2.) How can i set values to the variables in this class from my Controller and View classes ? 3.) How can i retrieve the values of these variables from this class (global variable class) ?

note: I know how to add it to the app.js and write/read from other classes. But i want to have a separate class for global variables.

like image 936
Sharon Watinsan Avatar asked Jul 13 '26 14:07

Sharon Watinsan


1 Answers

Add them as statics in a new class:

Ext.define('MyApp.util.Utilities', {
    statics: {
        myGlobal: 1
    }
});

At which point you load the class up and from anywhere in the app you can write MyApp.util.Utilities.myGlobal = 5.

This is an extension of my answer here to a similar problem: Where should I define global functions in ExtJS 4 MVC?

like image 82
David Kanarek Avatar answered Jul 15 '26 04:07

David Kanarek