View Full Version : Variables accessible from all controller functions? (MVC)

13 Dec 2012, 2:13 PM
Hey all,

I'm using the MVC application structure. I've got a controller with quite a few functions in it. They all access a lot of the same components in my application but I think I've written it very inefficiently.

For example, I have several buttons that affect the grid in my application. In each button function I have to do something like

var panel = button.up(panel);
var grid = panel.down(grid);

Instead of having those two lines in each button function, is there somewhere in the controller where I can define panel and grid (and the other components in my application) so they can be accessed by all my controller functions?

thank you!

13 Dec 2012, 3:17 PM
You can try the references:

extend : 'Ext.app.Controller',

refs : [
{ref:'grid',selector:'acontainer anotherpanel grid[itemId=yourId]'}

aFunction : function(){

First you define a reference with a selector, then you can access that reference by a dynamic method called "getYourReferenceName".

These references are accesible only by the current controller.


27 Dec 2012, 3:12 PM
Thank you, I've done some more reading about references now.

So you can refer to specific instances of views in your app right? And once defined, calling a reference should be faster than doing a component query?