Reputation: 795
I'm working with a partner to build a Sencha Touch 2 database app. He's built a ton of methods for me on the backend, with syntax like this:
Each of which expects a POST to be sent with it.
What I'm struggling with is what the proxies should look like - for instance, is there a way to specify a show proxy that maps /update /add and /delete to their associated U/C/D actions? There's only one url in the proxy, and that is for the get action (getByUser in this case)
I'm assuming that I want to put the other actions into the proxy somehow - or do I just need a bunch of different proxies for each action (that seems kinda redundant...)
The Sencha docs imply that CRUD actions are built-in to proxies, but I don't see where or how their urls get defined...
Ext.define('SMToolkit.store.Shows', {
extend: 'Ext.data.Store',
config: {
model: 'SMToolkit.model.Show',
autoLoad: true,
sorters: 'name',
grouper: {
groupFn: function(record) {
return record.get('type');
}
},
proxy: {
type: 'ajax',
url : 'index.php?r=show/getByUser&username=FOO'
}
}
});
With a model that looks like this:
Ext.define('SMToolkit.model.Show', {
extend: 'Ext.data.Model',
config: {
fields: [
'id',
'name',
'opening',
'closing',
'rehearsal',
'type',
'availability'
]
}
});
Upvotes: 1
Views: 2351
Reputation: 26
When you should have a specific URL for each operation, ST2 provides you with the API property. You should change your proxy to:
proxy: {
type: 'ajax',
api: {
create : 'index.php?r=show/add',
read : 'index.php?r=show/read',
update : 'index.php?r=show/update',
destroy: 'index.php?r=show/delete'
}
}
Please note I removed the url property and added the api property. Also, to delete, you must enter the word 'destroy' because, in Javascript, 'delete' is a reserved word.
Upvotes: 1