Fork me on GitHub

Response plugins


A Jaxon response plugin enriches the Jaxon\Response\response class with new functions. It therefore adds new features into webpages, for example display windows dialogs or graphs.

Installation

To install a Jaxon Response plugin, install the corresponding package with Composer. Once installed, the plugin is automatically registered with the Jaxon library, and its CSS and javascript are automatically added to those generated by the library.

Configuration

The response plugins are configured in the same way as the Jaxon library, except that the parameter names are prefixed with the name of the plugin.

The documentation of each plugin provides a list of its configuration settings.

Usage

A Jaxon response plugin has a name, which must be unique across the application. This name provides access to an instance of the plugin from an object of class Jaxon\Response\Response.

The following example displays a notification in a webpage using the Dialogs plugin. The expression $response->dialog gives access to the plugin instance.

class MyClass
{
    public function myMethod()
    {
        $response->dialog->success("You are now using the Toastr Notification plugin!!");
    }

Create a new plugin

A response plugin must inherit from the abstract class \Jaxon\Plugin\Response, and define the abstract method getName(), which returns its unique identifier. The methods getCss(), getJs(), getScript() et getReadyScript(), which all have default implementations, allow to customize the plugin CSS and javascript codes, which will then be included in the code generated by the library.

The plugin must then define its own functions. In order to be able to execute actions in a webpage, the response() method returns the Response object which called the plugin, and the addCommand() method adds a call to a Jaxon command in this same response.

Once the plugin is created, it must the be declared into the library using the jaxon_register_plugin() function, which takes an instance of the plugin as a unique parameter.