Instead of the preface
I have long wanted to publish something useful and finally decided to talk about Ext.Direct. I have not seen a single more or less extensive article in Russian on this topic, either it is not needed by anyone, or one of the two, however we begin.
What is Ext.Direct?
Ext.Direct has been available since extjs version 3.0. This is a package that allows for closer interaction between the server and the client. Recalling version 2.0+, I understand how I missed “direct”.
The capabilities of Ext.Direct are implemented in the Ext.data package classes ( DirectStore
), so the DirectStore
uses the JsonReader
as the reader. There is also an Ext.direct package, in particular, the PollingProvider
class implements periodic server polling at a specified interval. Well, Ext.Direct
, about it casually below and Ext.Direct.Transaction, an auxiliary class that is not directly called.
Let's start with the Store
. I will not explain what it is, who needs to understand it himself, and who does not understand it and does not need it.
The simplest option is to specify a remote method as a data source, specify directFn
as a parameter .
Simply? Oh yeah! The first days I was just ecstatic. However, this method does not implement the so-called CRUD
(create, read, update, delete) and if all of a sudden you need to not only receive information, but also delete or update it, you can use the api
Further, the remote function can be called directly:
Hmmm ... What else ... Here, for example, error handling:
On the server side, just call exception.
Throw new Exception(', !');
And it will be intercepted by the handler. Well, in general, you can intercept anything. The documentation explains how.
At the moment there are many implementations of the server side, the full list can be found here
As for PHP, there are implementations in pure PHP, as well as for various frameworks. I have so far had experience with the implementation written by Tommy Maintz. More details can be found here
The package consists of three classes:
What you need to do to make it work:
- Download and unpack,
- And everything can be used.
- is designed for client work, Router
- for server work, respectively. Well, CacheProvider
is also in Africa CacheProvider
, used to store PHP parsed classes in the cache, for which you will understand it a little later.api.php
And finally, api.php is included in this way.router.php
, our access point to the server part of Ext.Direct
Now directly to custom classes. A curious detail of this implementation is that the remote methods are, firstly, encapsulated into classes, and secondly, become available after manipulating the comments to the method, i.e. The author decided that it would be correct to parse PHP classes and extract comments from files, (IMHO) a pervert, of course, but who is perfect here ... By the way, therefore, you probably need caching.File.phpOrders.phpTest.php
By the way, one more note: the number of parameters of the function should correspond to the number of parameters passed, even if some of them are by default = null
PS Of course, it would be possible to describe everything in more detail, but then it will take more than one day, and time is limited (now it is clear why there is no more extensive review in Russian). Who really needs this is to start and everything will go like clockwork. That's all, thank you for your attention!
References:ExtJs documentation dev.sencha.com/deploy/dev/docs
Introduction to Ext.Direct www.sencha.com/blog/2009/05/13/introducing-ext-direct
Ext.Direct specification www.sencha.com/products/js/direct.php
Implementing the server side of ExtJs (list) www.sencha.com/forum/showthread.php?67992-Ext.Direct-Server-side-Stacks
PHP implementation by Tommy Maintz www.sencha.com/forum/showthread.php?68186-Alternative-Ext-Direct-PHP-Implementation