📜 ⬆️ ⬇️

Working with ExtJS in PHP - PHP-Ext Library


I can hardly be mistaken if I assume that the PHP language is quite popular, if not the most popular in web development. We will not analyze the reasons for this (and, moreover, the consequences), but concentrate on one small aspect, namely, how to develop complex AJAX web applications on PHP. And it’s not just developing, but using the ExtJS library , which allows you to create interfaces for these web applications, in your work. Of course, all this can be spread and the server side, on PHP or in any other language, absolutely will not know anything about the client part and the AJAX-library, just using JSON data and plain HTML. But you can do it differently - this approach is similar to the popular today Google Web Toolkit technology. We do not share anything, we simply write the application using one medium, one language and all features (both language and medium), and already the server independently generates the code for the client, fully automatically. Thus, you can completely (well or almost) not know and do not understand the layout, JavaScript and ExtJS, but write applications that will use this framework.

For the Java language, such solutions exist, and recently such a project, EXT GWT , even went under the wing of the ExtJS development company itself, becoming quite a serious professional solution. But what about other languages? Java, of course, is good and even excellent, but the soul and body want diversity, or simply do not want to relearn. For such cases, there are solutions. And one of them, for PHP, is called PHP-Ext .

This library is a set of classes, partially repeating classes from ExtJS, which are rewritten in PHP, with the added mechanism for generating the output JS-code, which, in fact, is sent to the browser for execution. The developer operates only with PHP - we include the library, initialize it, and then create the objects we need in the form of PHP classes, set the necessary properties for them, and at the end of the code simply cause the generation of JavaScript and send it to the browser.

Of course, this approach allows you to use all the features of your favorite development environments - syntax autocompletion, code highlighting, built-in debuggers, other code verification tools. - It is no secret that for PHP such tools are much more than for JavaScript.
')
The library code itself is quite large, but the current version is fully compatible with PHP 5, in particular, it uses all the available OOP features. The code itself is fairly well documented (although not ideal), and its structure conforms to the Zend Framework PHP Coding Standard , which is not often seen in developing amateur projects, this is an indicator of the seriousness of the development and, probably, hopes for its development (and suddenly the developer company ExtJS will take part in the project, just as it was done with ExtGWT, in this case, you can really talk about a start-up project, and, moreover, very successful). For developers, there are several examples of working with sample objects, for example, forms - without inventing their own examples, the authors of the library simply remade those that come in the standard ExtJS package, rewriting them using their library. This is a great way to look at its real capabilities and even compare the generated code. Well, for in-depth study there is an API reference generated by comments in the code using phpDocumentator.

So far, however, not all the possibilities have been implemented, although there are enough of them for building relatively complex applications. In some shortcomings, with a reservation to the novelty of the project, I would write down the use of the previous version of ExtJS - 2.0.2 (although it works with 2.0.1), whereas now it is worth being guided by 2.1. But this will be corrected, because now only the second release is number 0.8.2, so for now we believe that we are simply improving the technology.

The development potential of the library is very large, in particular, both along the path of a more complete transfer of the entire ExtJS API to PHP, and towards improving the platform itself. For example, it would be logical to have in the code generator means for compressing the code, removing unused modules (based on the classes used and their dependencies, the server can build a set of necessary classes on the fly and generate an ExtJS assembly for your application, but for now it can be done manually online help). While the project is young, but it is developing fairly quickly, and if professionals and serious architecture stand behind its development, it can become an excellent tool for developing modern AJAX applications.

In my opinion, the option is still somewhat complicated, or rather, too much code and work with it to generate an interface, while you still need to clearly understand how the page is generated and how this JavaScript code will work, I think it’s even better know ExtJS and its capabilities than with the usual development, when the server side is completely unaware of the client. But some project that combines a template engine, for example, Smarty or Template Lite (my favorite) would be fantastic, if you simplify the creation and filling of complex templates. At the same time, since all the latest versions of ExtJS can generate a visual part using JSON markup, such as a form or a window, I see a lot of ways to simplify the server part, which would generate only the necessary minimum of JS code, and the main part of the page markup. - as JSON data. But this is a completely different architecture and approach.

And lastly, we will give one example, in order to clearly understand the mechanism of PHP-Ext. The following example displays a regular panel that can be collapsed and unfolded, one of the most used and versatile widgets in the library.

1. So the panel looks in the browser



2. This is how PHP code looks for generating this panel and setting its parameters.
  setTitle ("My Panel")
   -> setCollapsible (true)
   -> setRenderTo (PhpExt_Javascript :: variable ("Ext.get ('centercolumn')"))
   -> setWidth (400)
   -> setHtml (PhpExt_Javascript :: variable ("Ext.example.bogusMarkup"));  

 echo PhpExt_Ext :: OnReady (
	 $ p-> getJavascript (false, "p")
 );
 ?> 

3. This is the code that PHP-Ext generated to display this form (without the code of the page itself and the connection of the libraries).
  Ext.onReady (function () {
 var p = new Ext.Panel ({title: 'My Panel', collapsible: true,
 renderTo: Ext.get ('centercolumn'), width: 400, html:
 Ext.example.bogusMarkup});
 }); 

4. And this is the original code from the ExtJS examples.
  Ext.onReady (function () {
     var p = new Ext.Panel ({
         title: 'My Panel',
         collapsible: true
         renderTo: 'container',
         width: 400,
         html: Ext.example.bogusMarkup
     });
 }); 


PS Cross post from my blog.

Source: https://habr.com/ru/post/24592/


All Articles