Page 1 of 3 123 LastLast
Results 1 to 10 of 25

Thread: Dynamically loading MVC controller

  1. #1
    Sencha User
    Join Date
    Jul 2007
    Posts
    55
    Vote Rating
    1
      0  

    Default 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,

  2. #2
    Sencha Premium Member Fredric Berling's Avatar
    Join Date
    Sep 2007
    Location
    Sweden
    Posts
    198
    Vote Rating
    17
      0  

    Default 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() {
           
        }
    });

  3. #3
    Sencha User
    Join Date
    Jul 2007
    Posts
    55
    Vote Rating
    1
      0  

    Default

    Quote Originally Posted by Fredric Berling View Post
    Code:
    Ext.application({
        name: 'MyApp',
        controllers:['Users'],   //This is making the file "controllers/Users.js" load.
    
        launch: function() {
           
        }
    });
    @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?

  4. #4
    Sencha User ykey's Avatar
    Join Date
    Mar 2010
    Location
    USA
    Posts
    245
    Vote Rating
    28
      0  

    Default

    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.


  5. #5
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,323
    Vote Rating
    1294
      0  

    Default

    You can try the constructor or initComponent method
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    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 in print!

    When posting code, please use BBCode's CODE tags.

  6. #6
    Sencha User ykey's Avatar
    Join Date
    Mar 2010
    Location
    USA
    Posts
    245
    Vote Rating
    28
      0  

    Default

    Please explain or were you talking to olakara.

  7. #7
    Sencha User
    Join Date
    Jul 2007
    Posts
    55
    Vote Rating
    1
      0  

    Default

    Quote Originally Posted by mitchellsimoens View Post
    You can try the constructor or initComponent method
    Sorry, I didn't get the idea? can you explain further? or give us an example?

  8. #8
    Sencha User
    Join Date
    Jul 2007
    Posts
    33
    Vote Rating
    1
      1  

    Default

    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 !

  9. #9
    Sencha User ykey's Avatar
    Join Date
    Mar 2010
    Location
    USA
    Posts
    245
    Vote Rating
    28
      1  

    Default

    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).
    Attached Files Attached Files

  10. #10
    Sencha User
    Join Date
    Jul 2007
    Posts
    33
    Vote Rating
    1
      0  

    Default

    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.

Page 1 of 3 123 LastLast

Similar Threads

  1. newbie issue -- problems loading controller
    By JKeane in forum Ext: Discussion
    Replies: 2
    Last Post: 27 Apr 2011, 12:52 PM
  2. Loading ext-all.js dynamically
    By arajagop in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 18 Oct 2008, 4:49 AM
  3. dynamically loading script into dynamically added iframe in IE
    By markpele in forum Ext 2.x: Help & Discussion
    Replies: 6
    Last Post: 13 Dec 2007, 4:50 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •