1. #1
    Sencha User
    Join Date
    Sep 2011
    Posts
    118
    Answers
    7
    Vote Rating
    5
    subimage is on a distinguished road

      0  

    Default Answered: How do I get an instance of my main controller to manipulate from the console?

    Answered: How do I get an instance of my main controller to manipulate from the console?


    Assuming I have this code as my app initialize...how do I get the instantiated instance of CbMobile.controller.Main which I can run code against in the console?

    Code:
    Ext.Loader.setConfig({ enabled: true });
    
    
    Ext.application({
      name: 'CbMobile',
      controllers: [
        // Base classes
        'Base',
        'CrudBase',
        //
        'Contacts',
        'Expenses',
        'Main',
        'Projects',
        'Settings',
        'Timesheet'
      ],
      models: ['Section']
    });

  2. Declare a global variable in your app.js just before (or after) enabling Ext.Loader :

    Code:
    var consoleCtrl = null;
    Instantiate it with your desired controller inside the launch method of your application :

    Code:
    launch: function() {
        consoleCtrl = this.getController('Main');
    
        // More stuff
    }
    You can now use consoleCtrl as a reference to your controller from the console.

  3. #2
    Sencha User DrunkenBeard's Avatar
    Join Date
    May 2011
    Posts
    55
    Answers
    2
    Vote Rating
    -2
    DrunkenBeard has a little shameless behaviour in the past

      -2  

    Default


    Declare a global variable in your app.js just before (or after) enabling Ext.Loader :

    Code:
    var consoleCtrl = null;
    Instantiate it with your desired controller inside the launch method of your application :

    Code:
    launch: function() {
        consoleCtrl = this.getController('Main');
    
        // More stuff
    }
    You can now use consoleCtrl as a reference to your controller from the console.

  4. #3
    Sencha User
    Join Date
    Sep 2011
    Posts
    118
    Answers
    7
    Vote Rating
    5
    subimage is on a distinguished road

      0  

    Default


    Aha...OK thanks. I thought there might be a more "sencha" way to do that, or thought perhaps it automatically created some globs when making my apps and controllers.

  5. #4
    Sencha User
    Join Date
    Jul 2008
    Posts
    16
    Answers
    1
    Vote Rating
    5
    jearlu is on a distinguished road

      5  

    Default The "sencha" way

    The "sencha" way


    The more "sencha" way of doing this (without declaring a global variable) would be:
    Code:
    CbMobile.app.getController('Main');

  6. #5
    Sencha User
    Join Date
    Jul 2012
    Posts
    13
    Vote Rating
    3
    fousheezy is on a distinguished road

      1  

    Default


    Quote Originally Posted by jearlu View Post
    The more "sencha" way of doing this (without declaring a global variable) would be:
    Code:
    CbMobile.app.getController('Main');
    Please note that CbMobile is the app's namespace you defined in app.js and should be changed accordingly

    You can find your app's namespace in app.js
    Code:
    Ext.application({
        name: ' -- namespace goes here -- ',

  7. #6
    Sencha User
    Join Date
    Jul 2012
    Posts
    12
    Answers
    1
    Vote Rating
    0
    dbabyak is on a distinguished road

      0  

    Default


    doesn't work for me.

  8. #7
    Sencha User
    Join Date
    Apr 2013
    Posts
    9
    Vote Rating
    0
    frayjusto is on a distinguished road

      0  

    Default Use full controller namespace

    Use full controller namespace


    If you're declaring your MVCs in app.js, you'll want to make the getController call with the full namespace; otherwise you'll end up with a new instance of your controller, and not the actual controller that's already working in your app.

    Not sure why this is, because in app.js you list controllers without the namespace (controllers: ['Main', 'Etc'])... I guess the devs just want us to type a lot.

    eg:
    Code:
    CbMobile.app.getController('CbMobile.controller.Main');
    vs.
    Code:
    CbMobile.app.getController('Main');

  9. #8
    Sencha User
    Join Date
    Aug 2012
    Location
    Vancouver, Canada
    Posts
    29
    Answers
    1
    Vote Rating
    1
    trevorcox is on a distinguished road

      0  

    Default


    Not sure where this ".app" part comes from. I just use
    myapp.getController('myapp.controller.Main');