-
8 May 2011 4:06 AM #1
Dynamically loading MVC controller
Dynamically loading MVC controller
Looking at the existing docs and code, I don't think its possible. But, Is there any possibility of dynamically loading controllers to MVC application?
Here is what I am planning to do: I have few controllers that are not needed by certain users of the application. And also need to load few modules only if user is accessing it. The first case is basically an access control method.
Is it possible to execute code before the controllers are instantiated? Or make few controllers and classes load dynamically? Any ideas and suggestions are welcome.
Thanks in advance,
-
8 May 2011 5:31 AM #2
Just mention your controller in controller array in Ext.application
Just mention your controller in controller array in Ext.application
Code:Ext.application({ name: 'MyApp', controllers:['Users'], //This is making the file "controllers/Users.js" load. launch: function() { } });
-
8 May 2011 6:58 AM #3
@Fredric, I am aware of that.. my question is can i make array dynamic? For example, I need to add or remove controllers after the application is loaded Or before the application is loaded.
I see that launch() method is called after initialization of all the controllers.. but is there a way to access these before being initialized or after?
-
8 May 2011 7:23 AM #4
On a related note I have tried without success to instantiate a controller without an application being defined. The two are extremely coupled to each other. This has made unit testing controller code impossible without an application being loaded.

-
8 May 2011 8:11 AM #5Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,599
- Vote Rating
- 434
You can try the constructor or initComponent method
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.
-
8 May 2011 8:19 AM #6
Please explain or were you talking to olakara.
-
8 May 2011 9:09 PM #7
-
22 May 2011 9:28 AM #8
Hello,
with extJS 3.x i've built a similar architecture. i tried with extjs 4.x a proof of concept to load dynamically controllers. Here is how i do this:
1) You need an Application (says 'app.js') with at least 1 controller (says 'users')
2) in my view 'user' that is linked to controller 'users' i add a simple button
3) in controller 'users', add a listener to the 'click' event of view 'user' button
4) in click event handler in controller 'users', just call method 'this.getController('newController')'
5) ExtJs4 MVC will synchronously load the 'newController' file and add it to the application 'app.js'
6) to handle dynamic adding of controllers, in application 'launch' method, i add an event handler for 'add' event of 'controllers' property. So this way i can call the controller 'init' method (says with 'object.init()')
Is this answer your problem ? You can see my test source files : Users.zip
Now, i'm still thinking the best way to handle/manage view replacement in viewport after adding a controller. To be continued !
-
23 May 2011 8:19 PM #9
yd thanks for your post. it got me headed in what I think is a good direction.
I also want to destroy old controllers and views when they are not being used. I've attached a sample that shows how I am doing this (at least I think I am needs more testing).
-
23 May 2011 9:35 PM #10
Thanks ykey,
i've ever not looked at the API to check Ext singleton allow a "destroy" method ! I'll try it in my "proof of concept" application.
Similar Threads
-
newbie issue -- problems loading controller
By JKeane in forum Ext: DiscussionReplies: 2Last Post: 27 Apr 2011, 12:52 PM -
Loading ext-all.js dynamically
By arajagop in forum Ext 2.x: Help & DiscussionReplies: 2Last Post: 18 Oct 2008, 4:49 AM -
dynamically loading script into dynamically added iframe in IE
By markpele in forum Ext 2.x: Help & DiscussionReplies: 6Last Post: 13 Dec 2007, 4:50 AM


Reply With Quote