-
15 Oct 2011 9:46 PM #1
Answered: How do I get an instance of my main controller to manipulate from the console?
Answered: How do I get an instance of my main controller to manipulate from the console?
Assuming I have this code as my app initialize...how do I get the instantiated instance of CbMobile.controller.Main which I can run code against in the console?
Code:Ext.Loader.setConfig({ enabled: true }); Ext.application({ name: 'CbMobile', controllers: [ // Base classes 'Base', 'CrudBase', // 'Contacts', 'Expenses', 'Main', 'Projects', 'Settings', 'Timesheet' ], models: ['Section'] });
-
Best Answer Posted by DrunkenBeard
Declare a global variable in your app.js just before (or after) enabling Ext.Loader :
Instantiate it with your desired controller inside the launch method of your application :Code:var consoleCtrl = null;
You can now use consoleCtrl as a reference to your controller from the console.Code:launch: function() { consoleCtrl = this.getController('Main'); // More stuff }
-
16 Oct 2011 1:54 AM #2
Declare a global variable in your app.js just before (or after) enabling Ext.Loader :
Instantiate it with your desired controller inside the launch method of your application :Code:var consoleCtrl = null;
You can now use consoleCtrl as a reference to your controller from the console.Code:launch: function() { consoleCtrl = this.getController('Main'); // More stuff }
-
16 Oct 2011 12:25 PM #3
Aha...OK thanks. I thought there might be a more "sencha" way to do that, or thought perhaps it automatically created some globs when making my apps and controllers.
-
14 Mar 2012 4:20 PM #4
The "sencha" way
The "sencha" way
The more "sencha" way of doing this (without declaring a global variable) would be:
Code:CbMobile.app.getController('Main');
-
5 Jul 2012 6:14 AM #5
-
6 Dec 2012 8:33 AM #6
-
15 Apr 2013 10:21 AM #7
Use full controller namespace
Use full controller namespace
If you're declaring your MVCs in app.js, you'll want to make the getController call with the full namespace; otherwise you'll end up with a new instance of your controller, and not the actual controller that's already working in your app.
Not sure why this is, because in app.js you list controllers without the namespace (controllers: ['Main', 'Etc'])... I guess the devs just want us to type a lot.
eg:
vs.Code:CbMobile.app.getController('CbMobile.controller.Main');
Code:CbMobile.app.getController('Main');


Reply With Quote