Quick links: Content - sections - sub sections
EN FR

Adding coordinator (jelix core class) plugins allows you to customize different steps of the processing of any action.

You can execute some code, at process start, before action execution, after action execution (but before display), at process end.

Note: Coordinator plugins are commonly named coord plugin in Jelix.

Activate a coord plugin

You need to modify entry point configuration file. It could be var/config/index/config.ini.php if it is for index.php.

  • add its repository e.g the parent directory of your plugin.
  • Add the plugin name to [coordplugins] sections and set it ot "1" or to the configuration file name if needed.

Example: your plugin is located in foo folder of <application name>/plugins/coord/. Your config file should look like:


[coordplugins]
foo = foo.plugin.ini.php

foo.plugin.ini.php is a dedicated config file. Its content and structure depends only on the plugin. Having a plugin configuration file is not required. In that case, you should assign 1 to your plugin name:


[coordplugins]
foo = 1

The value "1" means also that the configuration of the plugin can be inside the configuration file of the entry point. It should be into a [coordplugin_XXX] section (where XXX is the name of the plugin, like [coordplugin_foo]).

Important: If you are using several coordinator plugins, the order of the plugins declaration in the config file matters. Hence the first declared plugin has precedence on the others. It means that if this first plugin returns an action, the other ones will not be executed. So you need to choose carefully the order of the plugins declaration according to the priority you wish for every plugin. For example if you consider that the bar plugin cannot be executed as long as the foo plugin does not return any action, then you should declare them this way:


[coordplugins]
foo = foo.plugin.ini.php
bar = 1

Plugin configuration

A plugin may need some configuration parameters

In order to configure a plugin, you might have declared a specific configuration file (see above). It is an ini file, located in var/config/. Its content will be passed as an array parameter to your plugin constructor.

If this is only a section [coordplugin_XXX] as indicated above, its content will be passed as an array parameter to your plugin constructor.

Plugin parameters

As said before, your plugin might need some options or parameters. Some of one can be set within controllers. Indeed, your plugin might do different treatments for each controller actions.

As an example, jAuth plugin checks if an action needs authentication or not. Each controller will set a parameter for each action indicating wether authentication is needed.

There is a member of the controller to serve this purpose: pluginParams. It is an associative array. Its keys are method names (actions names) and its values are arrays setting all plugins parameters. The key * covers all methods or actions.

Code Example:



public $pluginParams = array(
      '*'=>array('auth.required'=>false)
    );

Result: the plugin parameter auth.required is set to false for all methods.

See the documentation of the plugin to know which parameters you can use.

Plugin development

Concretely a plugin must implement jICoordPlugin interface. And so declare the following methods:


    public function __construct($config);
    public function beforeAction($params);
    public function beforeOutput();
    public function afterProcess ();

Class constructor receive its plugin configuration.

beforeAction method received plugin parameters set by controllers. It can return null if all is ok, or an object jSelectorAct (action selector) if another action must be executed (sort of redirection).

beforeOutput will be called after action execution.

afterProcess method will be called at the end of coordinator processing, thus just before display.

The class must be located in a plugins repository: plugins/ application folder or a plugins/ module folder are possible candidates. See page on plugins.

For an example plugin:

  • plugin folder will be plugins/coord/example/.
  • its file will be plugins/coord/example/example.coord.php
  • its class will be CexampleCoordPlugin and will implement jICoordPlugin interface.