PHP Classes
elePHPant
Icontem

Jaxon for Zend Framework: Zend plugin to call PHP classes from with AJAX

Recommend this page to a friend!
  Info   View files Documentation   Demos   View files View files (13)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2017-09-24 (1 month ago) RSS 2.0 feedStarStarStar 54%Total: 57 This week: 1All time: 9,007 This week: 599Up
Version License PHP version Categories
jaxon-zend 2.0.1BSD License5PHP 5, Libraries, AJAX
Description Author

This package integrates the Jaxon library with the Zend Framework 2 and 3, allowing to make AJAX calls to PHP classes.

This package automatically export all PHP classes installed in a given directory to Javascript, so their methods can be called directly from the browser.

The Jaxon library provides a Response object that allows in the PHP application to modify the content and layout of a page, and execute Javascript code on the client side.

  Performance   Level  
Name: Thierry Feuzeu <contact>
Classes: 11 packages by
Country: Cameroon Cameroon
Age: 41
All time rank: 27273 in Cameroon Cameroon
Week rank: 174 Up1 in Cameroon Cameroon Up
Innovation award
Innovation award
Nominee: 1x

Details

Jaxon Library for Zend Framework

This package integrates the Jaxon library with the Zend Framework 2.3+ and 3.

Features

  • Automatically register Jaxon classes from a preset directory.
  • Read Jaxon options from a config file.

Installation

Add the following lines in the composer.json file, and run the composer update command.

"require": {
    "jaxon-php/jaxon-zend": "~2.0"
}

Add the Jaxon module to the modules entry in the config/application.config.php or config/modules.config.php config file.

    'modules' => array(
        'Application',
        'Jaxon\Zend',
    ),

Zend Framework 2

Edit the module/Application/config/module.config.php as follow.

1. Import the Jaxon classes into the current namespace

use Jaxon\Zend\Factory\Zf2ControllerFactory;

2. Register the Jaxon plugin with the Service Manager

    'service_manager' => array(
        'invokables' => array(
            'JaxonPlugin' => 'Jaxon\Zend\Controller\Plugin\JaxonPlugin',
        ),
    ),

3. Use the provided factory to create both the application controller and the Jaxon ZF controller.

    'controllers' => array(
        'factories' => array(
            'Application\Controller\Demo' => Zf2ControllerFactory::class,
            'Jaxon\Zend\Controller\Jaxon' => Zf2ControllerFactory::class,
        ),
    ),

This factory injects the Jaxon plugin into the ZF controller constructor.

4. Route the Jaxon request URI to the plugin controller.

    'router' => array(
        'routes' => array(
            // Route to the Jaxon request processor
            'jaxon' => array(
                'type' => 'Zend\Mvc\Router\Http\Literal',
                'options' => array(
                    'route'    => '/jaxon',
                    'defaults' => array(
                        'controller' => 'Jaxon\Zend\Controller\Jaxon',
                        'action'     => 'index',
                    ),
                ),
            ),
        ),
    ),

Zend Framework 3

Edit the module/Application/config/module.config.php file as follow.

  1. Import the Jaxon classes into the current namespace
use Jaxon\Zend\Factory\Zf3ControllerFactory;
use Jaxon\Zend\Controller\Plugin\JaxonPlugin;
use Jaxon\Zend\Controller\JaxonController;

  1. Register the Jaxon plugin with the Service Manager
    'service_manager' => array(
        'invokables' => array(
            'JaxonPlugin' => JaxonPlugin::class,
        ),
    ),

Or

    'service_manager' => array(
        'factories' => array(
            JaxonPlugin::class => InvokableFactory::class,
        ),
        'aliases' => array(
            'JaxonPlugin' => JaxonPlugin::class,
        ),
    ),

  1. Use the provided factory to create both the application controller and the Jaxon ZF controller.
    'controllers' => [
        'factories' => [
            Controller\DemoController::class => Zf3ControllerFactory::class,
            JaxonController::class => Zf3ControllerFactory::class,
        ],
    ],

This factory injects the Jaxon plugin into the ZF controller constructor.

  1. Route the Jaxon request URI to the Jaxon Controller
    'router' => [
        'routes' => [
            // Route to the Jaxon request processor
            'jaxon' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/jaxon',
                    'defaults' => [
                        'controller' => JaxonController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
        ],
    ],

Configuration

The config of the Jaxon library is defined in the config/jaxon.config.php file. A sample config file is provided in this repo.

The settings in the config/jaxon.config.php config file are separated into two sections. The options in the lib section are those of the Jaxon core library, while the options in the app sections are those of the Zend Framework application.

The following options can be defined in the app section of the config file.

| Name | Description | |------|---------------| | classes | An array of directory containing Jaxon application classes | | views | An array of directory containing Jaxon application views | | | | |

By default, the views array is empty. Views are rendered from the framework default location. There's a single entry in the classes array with the following values.

| Name | Default value | Description | |-----------|-----------------|-------------| | directory | {app_dir}/jaxon/Classes | The directory of the Jaxon classes | | namespace | \Jaxon\App | The namespace of the Jaxon classes | | separator | . | The separator in Jaxon class names | | protected | empty array | Prevent Jaxon from exporting some methods | | | | |

Usage

This is an example of a Zend Framework controller using the Jaxon library.

namespace Application\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Jaxon\Zend\Controller\Plugin\JaxonPlugin;

class DemoController extends AbstractActionController
{
    /
     * @var \Jaxon\Zend\Controller\Plugin\JaxonPlugin
     */
    protected $jaxon;

    public function __construct(JaxonPlugin $jaxon)
    {
        $this->jaxon = $jaxon;
    }

    public function indexAction()
    {
        // Call the Jaxon module
        $this->jaxon->register();

        $view = new ViewModel(array(
            'jaxonCss' => $this->jaxon->css(),
            'jaxonJs' => $this->jaxon->js(),
            'jaxonScript' => $this->jaxon->script(),
        ));
        $view->setTemplate('demo/index');
        return $view;
    }
}

Before it prints the page, the controller makes a call to $jaxon->register() to export the Jaxon classes. Then it calls the $jaxon->css(), $jaxon->js() and $jaxon->script() functions to get the CSS and javascript codes generated by Jaxon, which it inserts into the page.

The Jaxon classes

The Jaxon classes must inherit from \Jaxon\Sentry\Armada. By default, they are loaded from the jaxon/Classes dir at the root of the Zend Framework application, and the associated namespace is \Jaxon\App.

This is a simple example of a Jaxon class, defined in the jaxon/Classes/HelloWorld.php file.

namespace Jaxon\App;

class HelloWorld extends \Jaxon\Sentry\Armada
{
    public function sayHello()
    {
        $this->response->assign('div2', 'innerHTML', 'Hello World!');
        return $this->response;
    }
}

Check the jaxon-examples package for more examples.

Request processing

By default, the Jaxon request are handled by the controller in the src/Controller/JaxonController.php file. The /jaxon route is linked by default to the JaxonController::actionIndex() method.

The request processing can be customized by extending the default controller and overloading the following method.

  • public function initInstance($instance): called for any Jaxon class instanciated.
  • public function beforeRequest($instance, $method, &$bEndRequest): called before processing the request.
  • public function afterRequest($instance, $method): called after processing the request.

See [https://www.jaxon-php.org/docs/armada/bootstrap.html]() for more information about processing callbacks.

Contribute

  • Issue Tracker: github.com/jaxon-php/jaxon-zend/issues
  • Source Code: github.com/jaxon-php/jaxon-zend

License

The package is licensed under the BSD license.

  Jaxon for ZF DemoExternal page  
  Files folder image Files  
File Role Description
Files folder imageconfig (1 file)
Files folder imagesrc (4 files, 2 directories)
Accessible without login Plain text file .styleci.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  config  
File Role Description
  Accessible without login Plain text file jaxon.config.php Aux. Auxiliary script

  Files folder image Files  /  src  
File Role Description
Files folder imageController (1 file, 1 directory)
Files folder imageFactory (2 files)
  Accessible without login Plain text file Module.php Class Class source
  Accessible without login Plain text file Session.php Class Class source
  Accessible without login Plain text file Session.php Class Class source
  Accessible without login Plain text file View.php Class Class source

  Files folder image Files  /  src  /  Controller  
File Role Description
Files folder imagePlugin (1 file)
  Accessible without login Plain text file JaxonController.php Class Class source

  Files folder image Files  /  src  /  Controller  /  Plugin  
File Role Description
  Accessible without login Plain text file JaxonPlugin.php Class Class source

  Files folder image Files  /  src  /  Factory  
File Role Description
  Accessible without login Plain text file Zf2ControllerFactory.php Class Class source
  Accessible without login Plain text file Zf3ControllerFactory.php Class Class source

Downloadjaxon-zend-2017-09-24.zip 9KB
Downloadjaxon-zend-2017-09-24.tar.gz 6KB
Install with ComposerInstall with Composer
Needed packages  
Class DownloadWhy it is needed Dependency
Jaxon Sentry Download .zip .tar.gz Uses the provided features Required
 Version Control Unique User Downloads Download Rankings  
 92%
Total:57
This week:1
All time:9,007
This week:599Up
 User Ratings  
 
 All time
Utility:75%StarStarStarStar
Consistency:83%StarStarStarStarStar
Documentation:83%StarStarStarStarStar
Examples:-
Tests:-
Videos:-
Overall:54%StarStarStar
Rank:1880