-
28 Apr 2012 4:57 AM #1
Unanswered: Unable to create an instance of controller
Unanswered: Unable to create an instance of controller
Lets suppose I have a controller
When I do this var obj = new Application.controller.MyPlan();[/CODE]Code:Ext.define('Application.controller.MyPlan' ,{ extend : 'Ext.app.Controller', config: { id: 'nut', stores: [ 'plan' ], views: [ 'plan.get_plan', ], models: [ 'Plan' ], before: { }, control: { }, refs: { }, routes:{ 'plan' : 'get_plan', } }, get_plan: function(){ .................. .................. }, });
I get this Uncaught TypeError: Object #<Object> has no method 'getRouter'
Is there any other way to do this because when I use defjs it also says me that
Code:LOG Resolving 'lazyPlan'.sencha-touch.js:598 LOG Creating instance of 'Application.controller.MyPlan'. LOG Controller.js:475Uncaught TypeError: Object #<Object> has no method 'getRouter'
-
30 Apr 2012 6:05 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,582
- Vote Rating
- 433
- Answers
- 3101
You should use the controllers config in Ext.application to load and create the controllers.
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.
-
15 Aug 2012 12:21 PM #3
I know this is old, but I had the same problem and found the solution, so here it is:
MyAppName.app can be any reference to Ext.app.ApplicationCode:var newController = Ext.create( 'MyController.controller.name', { application: MyAppName.app } );
-
25 Oct 2012 4:34 PM #4
The following has the same error, somehow sencha touch has problems with singletons:
Ext.versionsCode:Ext.define('MyApp.controller.foo',{ singleton: true, extend: 'Ext.app.Controller', init: function(){} }); // throws error: // Uncaught TypeError: Object #<Object> has no method 'getRouter'
Object- core: Ext.Version.Ext.extend.constructor
- build: 0
- major: 4
- minor: 1
- patch: 0
- shortVersion: "410"
- version: "4.1.0"
- __proto__: F
- touch: Ext.Version.Ext.extend.constructor
- build: 0
- major: 2
- minor: 1
- patch: 0
- release: "beta2"
- shortVersion: "210"
- version: "2.1.0beta2"
- core: Ext.Version.Ext.extend.constructor
-
26 Oct 2012 5:25 AM #5Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,582
- Vote Rating
- 433
- Answers
- 3101
Remove the singleton: true property
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.
-
26 Oct 2012 9:41 AM #6
How do you suggest I setup a singleton without using this flag? Is there an easy way to set this up? I'm trying to use a single controller for modal windows so that opening multiple modals doesn't result in them overlaying each other, but I can imagine other applications for this sort of thing.
-
26 Oct 2012 9:52 AM #7Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,582
- Vote Rating
- 433
- Answers
- 3101
All you need to do for controllers is add the name of it in the controllers array in Ext.application and the controller will be instantiated and used.
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 Jan 2013 10:14 AM #8
This is hard to do in unit testing frameworks like Jasmine and makes testing individual units of code difficult. Do you have any suggestions how one could unit test a controller?


Reply With Quote