In an ExtJS application that uses MVC design, how can you query records from a php/mysql back end or call methods on the php back end while passing objects or array data?
All of the examples I have seen of models, proxy, MVC style, show simple examples such as
myModel.load(123, ...
All it does is load record with id 123. Most of the examples also show how to create records or update existing records.
But what if I want to load a user with first name of “John”?
It looks like MAYBE I need to use a Store?
In other environments (such as AMF messaging) I usually pass objects – for example, creating a ‘User’ object or collection, setting the name, the calling something like
userService.Load(userObject);
Then, on the server side I receive the request for “userService.load” (a method on the server), then receive the object, pull out what I need, and return a result object (or array collection).
Are there any examples on how to query using models/proxies in ExtJS?
Then, how to use objects? I thought the model would be the object and pass itself via the proxy definition?
I think you got it, somehow, wrong with Model, Model is just a definition of a data Model, think of it as a row definition on the client side, lets use some example:
We have on our backend a table for the orders, we might represent it on the frontend with a Model, like this:
That is a really simple Model, now, if i want to fetch just one order at the time, i can use the model to do it, like this:
But, on the other hand if i want to get all the orders (ex, for a user), i’ll do it with a
Store, stores manage collection of models, we can say its a view of a table with a collection of rows composed of structured data that you can define in yourModel, lets define a simple store that use our model:That’s about fetching data, how do you handle in your server with PHP, well, i believe that is another question.
About the ´Model´ passing itself via ´Proxy´ that is true when adding or updating ej:
Or:
Here you can get some more info about it too:
Ext Store docs
Ext Model docs
I hope this will get you started with Models and Stores.