-
2 Mar 2012 1:09 AM #1
Unanswered: How to define constants file in sencha touch 2.0
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 Mar 2012 7:00 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,617
- Vote Rating
- 435
- Answers
- 3102
You need to require the class and put it in app/util/Config.jsCode:Ext.define('MyApp.util.Config', { singleton : true, config : { foo : 'bar' }, constructor: function(config) { this.initConfig(config); this.callParent([config]); } });
Then anywhere you can use MyApp.util.Config.getFoo()Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
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 almost in print!
When posting code, please use BBCode's CODE tags.
-
2 Apr 2012 2:20 AM #3
Require class for constants..
Require class for constants..
I tested the solution, but I got everytime: Uncaught TypeError: Cannot read property 'Config' of undefined
My code was:The Config.js file is exactly an copy of the sample.Code:Ext.application({ controllers: [....], models: [.....], name: 'MyApp', views: ['...'], stores:['...'], ..... launch: function() { Ext.require('MyApp.util.Config'); ........ Ext.Ajax.request({ url: MyApp.util.Config.getUrlLocalProxy() + '/', .... }
Is there any else to do?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]); } });
Thanks,
Daniel
-
2 Apr 2012 3:18 AM #4
I have done everything exactly the same way as described by mitchell and I am able to solve my problem.
-
1 May 2012 9:24 AM #5
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() + '/', .... }
-
8 Aug 2012 7:31 AM #6
Is it possible to use a constants file when your application does not use the MVC pattern... ie....stand alone pages?
-
9 Aug 2012 4:19 AM #7
-
16 Nov 2012 6:59 AM #8
call by:Code:config : { foo : 'bar' }
works, but why? where is the wrapper function from?Code:... getFoo() ...
-
16 Nov 2012 7:01 AM #9
Sencha touch will automagically generate getters and setters for you.
-
16 Nov 2012 8:56 AM #10Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,617
- Vote Rating
- 435
- Answers
- 3102
The initConfig method call in AbstractComponent's constructor method sets off the getter/setter creation.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
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 almost in print!
When posting code, please use BBCode's CODE tags.


Reply With Quote
