PHP Classes

How to Develop PHP AJAX Applications Using Jaxon to Call PHP Code From JavaScript - Jaxon package blog

Recommend this page to a friend!
  All package blogs All package blogs   Jaxon Jaxon   Blog Jaxon package blog   RSS 1.0 feed RSS 2.0 feed   Blog How to Develop PHP AJ...  
  Post a comment Post a comment   See comments See comments (0)   Trackbacks (0)  

Author:

Viewers: 715

Last month viewers: 5

Package: Jaxon

The Jaxon PHP package allows PHP developers to create AJAX-based applications that can call PHP classes that run on the server from JavaScript code that runs on the browser.

Read this article to learn more about the Jaxon package capabilities and about the features of the latest releases like the views and sessions management function, a jQuery-like API to update the page content, the Armada and Sentry packages that provide more advanced features and a common foundation for integration packages with PHP frameworks.




Loaded Article

In this article you will learn:

What is the Jaxon Library Package

What is New in Jaxon

What is the Structure of Jaxon Packages Avaliable for  You to Use

What the Armada and Sentry Packages Can Do

How You Can Develop Your Application Classes

What Are the Planned Future Developments for Jaxon

How to Integrate the Jaxon Packages with PHP Frameworks like Laravel, CakePHP, CodeIgniter, Zend Framework and YII

How to Download the Jaxon Packages or Install Them with PHP Composer


What is the Jaxon Library Package

Jaxon is a fork of the Xajax PHP library . It brought a unique and original way to easily create AJAX Web applications with PHP.

It allows a web page to make direct Ajax calls to PHP classes that will in turn update its content as well as its layout, without reloading the entire page (server-side rendering).

Creating an Ajax Web application becomes very easy with Xajax, for a JavaScript call is enough to execute the most complex actions on the web page, these actions being programmed in PHP on the server.

Unfortunately, the development of the library was suspended in 2012, soon after the release of version 0.6, for reasons that remain unknown.

A new version of the library was first published on Github in February 2016, then renamed in March as Jaxon and published for the first time under that name. Soon after, in July 2016, version 1.0.0 was released.

It took over the main features of Xajax, but with a completely re-written code, separating the library into one Javascript package and several PHP packages, using Composer for installation, as well as some plugins.

At the end of December 2016, the first beta build of version 2 was released. 7 months, 117 commits and 28 releases later, it was finally released in a stable version 2.0.0.

The Jaxon PHP library continues to be developed and maintained until these days.

What is New in Jaxon

In version 1, the major change is the ability to register PHP classes in a directory with a single line of code, taking their namespaces into account.

In addition, the library can be configured from a file, and the functions to generate the Ajax code that calls the PHP classes are enriched, especially with directories, namespaces, and pagination features.

The major changes in version 2 are the Armada and Sentry packages, the management of views and sessions feature, as well as the jQuery-PHP API.

Unit tests have also been added to the library, although the coverage is still to be improved.
The Armada and Sentry packages provide a base class that the classes of applications inherit from, and provide them with many functions.

They also offer a common API for managing views and sessions, which relies on functions provided by frameworks or other PHP libraries.

The jQuery-PHP API provides functions inspired by the Javascript jQuery library to update the content of the application pages in PHP.

The most important advantage of Armada and Sentry is the ability to reuse the classes of a Jaxon application with different PHP frameworks.

What is the Structure of Jaxon Packages Avaliable for  You to Use

The Jaxon library is composed of 4 main packages, and plugins that add functions or integrate it to PHP frameworks.

The main packages are:

- jaxon-core and jaxon-js, which respectively provide the PHP and Javascript functions.

- jaxon-sentry and jaxon-armada, which provide the most advanced functions, and a common platform for integration with PHP frameworks.

Integration packages simplify the use of Jaxon with the most common PHP frameworks.

They come in the form of a plugin for the framework concerned, with functions to load the configuration of Jaxon from a file in the format defined by the framework, and load the Jaxon classes from predefined directory and namespace.

They also provide an adapter that allows to use the Jaxon views and sessions management API with the functions provided by the framework.

A single integration package can be used in an application, depending on the framework used.

For frameworks that are not yet supported, the jaxon-armada package must be used.
Integration packages currently exist for 6 PHP frameworks:

- Symfony: https://github.com/jaxon-php/jaxon-symfony

- Laravel: https://github.com/jaxon-php/jaxon-laravel

- Zend Framework: https://github.com/jaxon-php/jaxon-zend

- Cake PHP: https://github.com/jaxon-php/jaxon-cake

- CodeIgniter: https://github.com/jaxon-php/jaxon-codeigniter

- Yii: https://github.com/jaxon-php/jaxon-yii

The Armada and Sentry packages provide a unique view API, which can be used with different template engines.

In a Jaxon application, views that use a given template engine are placed in a directory, which is then specified in the configuration with the engine id.

    'app' => array(
        'views' => array(
            'users' => array(
                'directory' => '/path/to/users/views',
                'extension' => '.tpl',
                'renderer' => 'smarty',
            ),
        ),
    ),

The id is then used in Jaxon classes to display the templates with the chosen engine.

   // Render the view at /path/to/users/views/path/to/view.tpl with Smarty
    $html = $this->view()->render('users::path/to/view');

The support for each template engine is implemented in a separate package, several of which can be used in the same application:

- Twig https://github.com/jaxon-php/jaxon-twig.

- Smarty https://github.com/jaxon-php/jaxon-smarty.

- Blade https://github.com/jaxon-php/jaxon-blade.

- Dwoo https://github.com/jaxon-php/jaxon-dwoo.

- Latte https://github.com/jaxon-php/jaxon-latte.

- RainTpl https://github.com/jaxon-php/jaxon-raintpl.

Finally, the jaxon-dialogs package provides a unique API that can be used with different Javascript libraries to display windows, confirmation dialogs, and notifications. As we are writing this article, 16 Javascript libraries are supported, and each user can add new ones.

What the Armada and Sentry Packages Can Do

The Armada and Sentry packages are the core of version 2. The Sentry package provides the classes and interfaces that implement or define all the library functions, whether it is for application class management, or for views and sessions management.

However, the package is not intended to be used directly by developers. The Armada package, that depends on Sentry, will provide them with all these functionalities.

It is worth noting that integration packages to PHP frameworks also depend on Sentry packages.

This allows to have common APIs for Jaxon applications, whether they use Armada or whether they are integrated into a PHP framework. In particular, a class of an application that uses these APIs can be reused without being modified with Armada as well as PHP frameworks.

This property is very interesting because it paves the way for the creation of complete application modules, with views and sessions functions, which can be compatible with several different PHP frameworks. That was not possible until today.

An example of such a module would be a user management application.

How You Can Develop Your Application Classes

The classes of a Jaxon Armada application can be located in several directories, each having a distinct namespace. All the directories are declared in the app.classes section of the configuration file.

The classes inherit from the Jaxon\Sentry\Armada class, which provides a large number of functions that are used to build the application.

- Updating the content and layout of the application pages. These are the functions that make it possible to manipulate the DOM (Document Object Model) of a web page, i.e modify its content (HTML) or its layout (CSS).

- Creating Ajax requests to application classes. These functions generate the Javascript code necessary to call the PHP classes of the application directly from the web page, and to link this code to events in the elements of the page.

- Managing views and sessions.

All these functions are defined or implemented in the Sentry package, which serves as the common foundation to the Armada package as well as all the other PHP framework integration packages.

Therefore, a class of an Armada application can be used with any supported PHP framework, without requiring any modification.

What Are the Planned Future Developments for Jaxon

They will be focused on three main points: enriching the library's ecosystem with more plugins, making it more reliable with more tests, and upgrading its Javascript library.

Regarding the first point, two new plugins are currently underway. The first is a plugin to display graphs on a Web page with several Javascript libraries to choose from.

It is drawn from the Laravel chart package (https://github.com/ConsoleTVs/Charts). The second is a complete user management module similar to Voyager (https://laravelvoyager.com) or LaraAdmin (http://laraadmin.com), but with much less functionalities. Based on Armada and Sentry, it will demonstrate the creation of cross-framework modules with Jaxon.

Currently, only a portion of the library code is covered by unit tests. The objective will consist of increasing the coverage of tests, and adding functional tests, so it is possible to validate the proper functioning of the library at the level of a Web page.

Finally, unlike PHP code, the JavaScript code of the library did not change that much. It would be interesting to use one or more micro-frameworks (http://microjs.com) to implement some of its functions, with the objective of reducing its size and adding tests.

How to Integrate the Jaxon Packages with PHP Frameworks like Laravel, CakePHP, CodeIgniter, Zend Framework and YII

The Jaxon package can be integrated with some of the most popular PHP frameworks. There are several additional packages that you can use to integrate Jaxon with your favorite PHP framework. Below you can find those packages:

Jaxon for CakePHP

Jaxon for CodeIgniter

Jaxon for Laravel

Jaxon for Symfony

Jaxon for YII

Jaxon for Zend Framework

How to Download the Jaxon Packages or Install Them with PHP Composer

The Jaxon package can be downloaded from download page or be installed using the PHP Composer tool following instructions in the Composer install instructions page.

You may also download or install with Composer the Jaxon Armada and Jaxon Sentry packages by going to the respective download pages for Jaxon Armada and Jaxon Sentry.




You need to be a registered user or login to post a comment

1,611,040 PHP developers registered to the PHP Classes site.
Be One of Us!

Login Immediately with your account on:



Comments:

No comments were submitted yet.



  Post a comment Post a comment   See comments See comments (0)   Trackbacks (0)  
  All package blogs All package blogs   Jaxon Jaxon   Blog Jaxon package blog   RSS 1.0 feed RSS 2.0 feed   Blog How to Develop PHP AJ...