Results 1 to 10 of 10

Thread: How to define constants file in sencha touch 2.0

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Sencha User
    Join Date
    Feb 2012
    Posts
    14
    Vote Rating
    0
      0  

    Default Unanswered: How to define constants file in sencha touch 2.0

    Hi,
    I want to make one properties file that will contain all the constants for my application. Can anyone please help me out how to do this in Sencha Touch 2.0 and how to access that file and constants defined in the file in my controllers, views and model. This property file will contain all my application specific constants as we do in Java.

    Thanks,
    Divya

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,422
    Answers
    3901
    Vote Rating
    1271
      0  

    Default

    Code:
    Ext.define('MyApp.util.Config', {
        singleton : true,
    
        config : {
            foo : 'bar'
        },
    
        constructor: function(config) {
            this.initConfig(config);
    
            this.callParent([config]);
        }
    });
    You need to require the class and put it in app/util/Config.js

    Then anywhere you can use MyApp.util.Config.getFoo()
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Apr 2012
    Posts
    6
    Vote Rating
    0
      0  

    Default Require class for constants..

    I tested the solution, but I got everytime: Uncaught TypeError: Cannot read property 'Config' of undefined

    My code was:
    Code:
    Ext.application({
        controllers: [....],
        models: [.....],
        name: 'MyApp',
        views: ['...'],
       stores:['...'],
       .....
        launch: function() {
        Ext.require('MyApp.util.Config');
        ........
        Ext.Ajax.request({
            url:  MyApp.util.Config.getUrlLocalProxy() + '/',
                    ....
    }
    The Config.js file is exactly an copy of the sample.

    Code:
    Ext.define('MyApp.util.Config', {
        singleton : true,
        config : {
            urlLocalProxy: '127.0.0.1/utilityProxy.php'
        },
        constructor: function(config) {
            this.initConfig(config);
            this.callParent([config]);
        }
    });
    Is there any else to do?

    Thanks,

    Daniel

  4. #4
    Sencha User
    Join Date
    Feb 2012
    Posts
    14
    Vote Rating
    0
      0  

    Default

    I have done everything exactly the same way as described by mitchell and I am able to solve my problem.

  5. #5
    Sencha User
    Join Date
    Aug 2011
    Location
    Belgium
    Posts
    29
    Answers
    4
    Vote Rating
    4
      0  

    Default

    I don't require it in launch-function, but in the application itself (and make sure the file is in the right folder: app/util/Config.js):
    Code:
    Ext.application({
        requires: [  'MyApp.util.Config'  ],
        controllers: [....],
        models: [.....],
        name: 'MyApp',
        views: ['...'],
        stores:['...'],
       .....
        launch: function() {
        ........
        Ext.Ajax.request({
            url:  MyApp.util.Config.getUrlLocalProxy() + '/',
                    ....
    }

  6. #6
    Sencha Premium Member
    Join Date
    Nov 2011
    Posts
    24
    Answers
    2
    Vote Rating
    0
      0  

    Default

    Is it possible to use a constants file when your application does not use the MVC pattern... ie....stand alone pages?

  7. #7
    Sencha User
    Join Date
    Aug 2011
    Location
    Belgium
    Posts
    29
    Answers
    4
    Vote Rating
    4
      0  

    Default

    Quote Originally Posted by essex View Post
    Is it possible to use a constants file when your application does not use the MVC pattern... ie....stand alone pages?
    As long as you "require" the config-file with the constants, i think that is possible (if i understand it well).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •