6

I'm writing a simple Sencha Touch 2 Application with the new MVC Pattern of the Framework - so, there are models, stores, controllers and views and all is tied together with an Application.

Now, there is the possability to use "this.getApplication()" to get the instance of this super uber-class "Application".

And now there is the problem - getApplication() returns only the app-instance, if i'm in a controller - in a view, a model or a store, it is returning "undefined".

Basically, i can understand the idea behind this behavior - your business has to be in controllers, nowhere else.. and so you don't have to know the app-instance in stuff like stores, views or models...

Okey but.. it would be extremely nice to have global-properties living in the main-app.

For example, i want to define my webservice-url globally in the Application and use that variable everywhere i need to - and unfortunately, i need this url in a store too.

Now, the only way i see to access this global variable in a store is the way through my Namespace. Instead of using "this.getApplication().serviceUrl" i found only the solution through the namespace with "NameOfMyApp.app.serviceUrl" - and that could not be the best way to solve this.

Any ideas about that problematic? Is there a better, always working way to get the app instance from everywhere? Or, where should i store global variables if not in the Application?

jebbie
  • 1,418
  • 3
  • 17
  • 27

3 Answers3

3

You can access the application instance on the AppName.app property in the latest Sencha Touch 2 betas.

Ext.application({
    name: 'Sencha',

    launch: function() {
        // Logs the application instance
        console.log(Sencha.app);
    }
});
rdougan
  • 7,217
  • 2
  • 34
  • 63
  • Hey, thanks for your answer :) Yeah this possability i have noticed in the docs... but i think, that cannot be the best way to do that. What if you refactor the name of your app? this.getApplication() is app-name independant – jebbie Feb 17 '12 at 09:16
  • 1
    Unfortunately, there simply is no other way to do it. I work on Sencha Touch 2. :) – rdougan Feb 19 '12 at 02:00
  • 1
    This does not work when using: Sencha app build testing etc. The AppName object does no longer contain the "app" property. –  Oct 04 '12 at 13:55
1

looks like Ext.app.Application.appInstance is app name agnostic solution

olegtaranenko
  • 3,722
  • 3
  • 26
  • 33
1

I work with ExtJS 4.1.1a and Ext.app.Application.instance seems to be the only solution. From a controller you can use this.application.