PDA

View Full Version : [FIXED] Controller::init() not firing



olouvignes
13 Oct 2011, 5:31 AM
From Ext.app.Controller documentation :
http://docs.sencha.com/touch/2-0/#!/api/Ext.app.Controller



Ext.define('MyApp.controller.Users', {
extend: 'Ext.app.Controller',


init: function() {
console.log('Initialized Users! This happens before the Application launch function is called');
}
});


I never get the log (js has been loaded with no error). Init() is never called.

Is there something else to add to make this controller work in my app ?

olouvignes
13 Oct 2011, 5:36 AM
Found it :

You should add controllers to the Ext.application() :



Ext.application({
...
controllers: ['Users']
...
});

Got confused by the way the old regController worked.

Jamie Avins
13 Oct 2011, 7:32 AM
I think the documentation should be more clear about this as well.

ramachandran
9 Nov 2011, 3:02 AM
Found it :

You should add controllers to the Ext.application() :



Ext.application({
...
controllers: ['Users']
...
});

Got confused by the way the old regController worked.


i have added as it is but some issue still not loading.
Uncaught Error: Ext.Loader is not enabled, so dependencies cannot be resolved dynamically. Missing required class: Blog.controller.Users
this is the error i m getting pleases someone help

oddz
9 Nov 2011, 6:48 PM
// Auto loading is disabled by default… so merely enable it

Ext.Loader.setConfig({ enabled: true });


Ext.application({ ... controllers: ['Users'] ... });

ramachandran
9 Nov 2011, 11:58 PM
// Auto loading is disabled by default… so merely enable it

Ext.Loader.setConfig({ enabled: true });


Ext.application({ ... controllers: ['Users'] ... });



THANKS

got it.................

krislogy
21 May 2012, 4:45 AM
Hmmm... for me, neither of the two functions init( ) or launch( ) are being called.
There are no errors. Files, Objects and Classes are loading properly. But, just the functions arent being called.

My controller defn, and Ext.application code goes like this:


// Controller code ==================
Ext.define("MyApp.controller.Items", {
extend: 'Ext.app.Controller',

config: {
init: function () {
this.callParent(arguments);
alert('alo!!');
console.log(arguments);
},

launch: function () {
this.callParent(arguments);
alert('alo launch!!');
console.log(arguments);
},

control: {
items: {
tap: 'doTemp'
}
},

refs: {
myitems: 'itemsection myitem element'
}
},

doTemp: function () {
Ext.Msg.alert('Yippeee!', 'I controlled it!', Ext.emptyFn);
},
});


// Application code ==================
Ext.application({
name: 'MyApp',

controllers: [
'Items'
],

// --- other stuffs including launch() function

)};



I know I'm missing something. Some application-level config value?... dev mode -vs- production mode?... or something.
Please assist.

===
2nd thing (sorry to bring this up in the same thread, please remove/relocate it if necessary):
Check out my "refs" definition in above code => myitems: 'itemsection myitem element'
(itemsection and myitem are both custom classes extending Ext.Panels... where "itemsection" actually has 4-5 "myitem" items in it)
So is the refs defn correct for its element's 'tap' event to be detected properly?

Thanks!
Kris

ps/fyi: I also tried putting a launch function in the Kitchen Sink example code. That wasn't called either.

krislogy
21 May 2012, 5:17 AM
oh crud! sorry for the trouble. One should put the function not INSIDE the "config" property. But as a separate property... and it works.
But in my defense, it was hard to notice, as it wasn't clearly mentioned in the common docs/examples. Plus in the docs, it is given under "config" section.. so I'd thought anything under that should always be mentioned the same way when "extending" any base class... anyway.
Although, I would still want an answer to my other question.
Thanks!