PDA

View Full Version : MVC: How can I access controller methods/properties from view



viewsrc
20 Nov 2011, 1:34 PM
Hi everyone,

I have several views all depending on a "global" property.

I would like to set this on the controller


Ext.define('MyController', {
extend: 'Ext.app.Controller',
...
views: ['viewA', 'viewB', ...]
...
myProperty: 'foo'
...
}

Question:

How can I access myProperty from, e.g., the initComponent method of viewA

.getController('MyController').myProperty sounds like what I want but getController is only available from within other Controllers and Application...

Any ideas anyone?

skirtle
20 Nov 2011, 4:47 PM
This doesn't sound right to me. This couples your views to your controller too tightly.

I'm always a bit dubious about the use of global properties but if you really need to use one then it should probably be a static property, not an instance property. If it isn't truly global and needs to be scoped to the views for a particular controller then would it be possible to have the controller inject the property into the view, rather than the view trying to pull it off the controller? Reversing the dependency like this would remove the coupling issue.