|  Download Jaxon Library for Zend FrameworkThis 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.
 InstallationAdd the following lines in the composer.jsonfile, and run thecomposer updatecommand. "require": {
    "jaxon-php/jaxon-zend": "~3.1"
}
 Add the Jaxon module to the modulesentry in theconfig/application.config.phporconfig/modules.config.phpconfig file.     'modules' => [
        'Application',
        'Jaxon\Zend',
    ),
 Zend Framework 2Edit 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' => [
        'invokables' => [
            'JaxonPlugin' => 'Jaxon\Zend\Controller\Plugin\JaxonPlugin',
        ),
    ),
  3. Use the provided factory to create both the application controller and the Jaxon ZF controller.     'controllers' => [
        'factories' => [
            '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' => [
        'routes' => [
            // Route to the Jaxon request processor
            'jaxon' => [
                'type' => 'Zend\Mvc\Router\Http\Literal',
                'options' => [
                    'route'    => '/jaxon',
                    'defaults' => [
                        'controller' => 'Jaxon\Zend\Controller\Jaxon',
                        'action'     => 'index',
                    ),
                ),
            ),
        ),
    ),
 Zend Framework 3Edit the module/Application/config/module.config.php file as follow. 
Import the Jaxon classes into the current namespace
 use Jaxon\Zend\Factory\Zf3ControllerFactory;
use Jaxon\Zend\Controller\Plugin\JaxonPlugin;
use Jaxon\Zend\Controller\JaxonController;
 
Register the Jaxon plugin with the Service Manager
     'service_manager' => [
        'invokables' => [
            'JaxonPlugin' => JaxonPlugin::class,
        ],
    ],
 Or     'service_manager' => [
        'factories' => [
            JaxonPlugin::class => InvokableFactory::class,
        ],
        'aliases' => [
            'JaxonPlugin' => JaxonPlugin::class,
        ],
    ],
 
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. 
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',
                    ],
                ],
            ],
        ],
    ],
 ConfigurationThe config of the Jaxon library is defined in the config/jaxon.config.phpfile.
A sample config file is provided in this repo. The settings in the config/jaxon.config.phpconfig file are separated into two sections.
The options in thelibsection are those of the Jaxon core library, while the options in theappsections are those of the Zend Framework application. The following options can be defined in the appsection of the config file. | Name | Description |
|------|---------------|
| directories | An array of directory containing Jaxon application classes |
| views   | An array of directory containing Jaxon application views |
| | | | By default, the viewsarray is empty. Views are rendered from the framework default location.
There's a single entry in thedirectoriesarray 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 |
| | | | UsageThis 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()
    {
        $view = new ViewModel([
            '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 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 classesThe Jaxon classes can inherit from \Jaxon\CallableClass.
By default, they are loaded from thejaxon/Classesdir 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.phpfile. namespace Jaxon\App;
class HelloWorld extends \Jaxon\CallableClass
{
    public function sayHello()
    {
        $this->response->assign('div2', 'innerHTML', 'Hello World!');
        return $this->response;
    }
}
 Request processingBy default, the Jaxon request are handled by the controller in the src/Controller/JaxonController.phpfile.
The/jaxonroute is linked by default to theJaxonController::actionIndex()method. Contribute
Issue Tracker: github.com/jaxon-php/jaxon-zend/issues
Source Code: github.com/jaxon-php/jaxon-zend
 LicenseThe package is licensed under the BSD license. |