1. #1
    Sencha User
    Join Date
    Jul 2007
    Posts
    50
    Vote Rating
    0
    olakara is on a distinguished road

      0  

    Default 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,
    Thanks and Regards,
    Abdel Olakara.
    [ blog : http://technopaper.blogspot.com ]

  2. #2
    Sencha Premium Member Fredric Berling's Avatar
    Join Date
    Sep 2007
    Location
    Sweden
    Posts
    186
    Vote Rating
    15
    Fredric Berling has a spectacular aura about Fredric Berling has a spectacular aura about

      0  

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

  3. #3
    Sencha User
    Join Date
    Jul 2007
    Posts
    50
    Vote Rating
    0
    olakara is on a distinguished road

      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?
    Thanks and Regards,
    Abdel Olakara.
    [ blog : http://technopaper.blogspot.com ]

  4. #4
    Sencha User ykey's Avatar
    Join Date
    Mar 2010
    Location
    USA
    Posts
    245
    Vote Rating
    27
    ykey has a spectacular aura about ykey has a spectacular aura about

      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 - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,582
    Vote Rating
    814
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    You can try the constructor or initComponent method
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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
    27
    ykey has a spectacular aura about ykey has a spectacular aura about

      0  

    Default


    Please explain or were you talking to olakara.

  7. #7
    Sencha User
    Join Date
    Jul 2007
    Posts
    50
    Vote Rating
    0
    olakara is on a distinguished road

      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?
    Thanks and Regards,
    Abdel Olakara.
    [ blog : http://technopaper.blogspot.com ]

  8. #8
    Sencha User
    Join Date
    Jul 2007
    Posts
    33
    Vote Rating
    1
    yd290276 is on a distinguished road

      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
    27
    ykey has a spectacular aura about ykey has a spectacular aura about

      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

  10. #10
    Sencha User
    Join Date
    Jul 2007
    Posts
    33
    Vote Rating
    1
    yd290276 is on a distinguished road

      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.

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

Thread Participants: 17

Tags for this Thread