PDA

View Full Version : Extended Proxy does not load config



Gr3yh0und
22 Jan 2012, 2:16 PM
Hey,

I'm just trying to rewrite my hardcoded proxies with a new class. So far i got:


Ext.define('Application.ProxyAjax', {
extend: 'Ext.data.proxy.Ajax',
alias: 'widget.teststore',
autoSave: true,

constructor: function() {
this.url = 'config/api_mysql.php';
this.api = {
read: 'config/api_mysql.php?do=read',
update: 'config/api_mysql.php?do=update',
create: 'config/api_mysql.php?do=create',
destroy: 'config/api_mysql.php?do=destroy'
};
this.actionMethods = {
read: 'POST',
update: 'POST',
create: 'POST',
destroy: 'POST'
};
this.reader = {
type: 'json',
model: 'Open',
root: 'results',
totalProperty: 'total',
idProperty: 'id'
};
this.writer = {
type: 'json',
model: 'Open',
root: 'results',
encode: 'true'
};

this.callParent();
}
});

var proxy_open = Ext.create('Application.ProxyAjax');
//proxy_open.api.read = 'config/api_mysql.php?do=read';

Now when I check the "api" value with firebug its just nothing in it. It actually also doesn't load anything... when I set the api from outside it is working (as last line up there is showing).

Any ideas why it isn't working?

flanders
22 Jan 2012, 2:39 PM
The constructor of Ext.data.proxy.Server (= that of Ext.data.proxy.Ajax) sets api to the either config.api or an empty object. So your setting of api gets overwritten. (See: http://docs.sencha.com/ext-js/4-0/source/Server.html#Ext-data-proxy-Server)

Just change it to:



constructor: function(config) { // note the config!
config.api = {
... // whatever you wanna set
}

this.callParent([config]); // again, note the config!
}

flanders
22 Jan 2012, 2:41 PM
IMHO: Avoid using the constructor when possible, but stick to initComponent. But in both cases, the earlier you can do the ancestors constructor/initComponent, the better.

Do custom stuff later on. (I don't think languages like Java force you to call the parent constructor as the first thing you do ;))

Gr3yh0und
22 Jan 2012, 3:38 PM
Okay, got it right this was:


Ext.define('Application.ProxyAjax', {
extend: 'Ext.data.proxy.Ajax',
alias: 'widget.teststore',

config: {
url: 'config/api_mysql.php',
api: {
read: 'config/api_mysql.php?do=read',
update: 'config/api_mysql.php?do=update',
create: 'config/api_mysql.php?do=create',
destroy: 'config/api_mysql.php?do=destroy'
}
...
},

constructor: function(config) {
this.callParent(config);
this.initConfig(config);
}
});