Quick links: Content - sections - sub sections
EN

Trace: howto

Wiki: Sitemap - Recent Changes - Back link

How to create a plugin coordinator

The plugin permit to extend the possibilities of the framework / of your application

Its plugins are of 8 types :

  • Acl : Plugin of ACL management
  • Acl2 : Plugin of ACL v2 management
  • Auth : Authentification driver
  • Coord : Plugin Coordinator
  • Db : Database driver
  • Tpl : Plugin of template
  • Url : Plugin that permits to manage Urls
  • jForms: plugin of forms management

This article will address the plugin type "Coord".

A plugin coord permit to act before/during/after the action of a controler.

The advantage of this, is to code once and for all, a behavior when an action occurs, rather than putting in a business class that same code and call to each share with jClasses::inc();

It's more simpler and clearer to read and the controler is more maintenable.

A) Utilisation of plugins Coordinator :

Example : the plugin coord auth of jelix, permits to check if a user is identified.

Its installation is done by adding auth=auth.coord.ini.php in the section coordplugins in the file defaultconfig.ini.php

[coordplugins]
auth=auth.coord.ini.php

then adding adding the array $pluginParams in the controler.

Example 1 :

class adminCtrl extends jController {   
    public $pluginParams = array(
        '*'		=> array('auth.required'=>true));   
   ...
}

here, we ask to Jelix (by the auth coord) that the access of all the action (with the star '*') of the adminCtrl controler can be possible only if the user is identified.

Example 2 :

class adminCtrl extends jController {
    public $pluginParams = array(
        '*'	=>	
             array('auth.required'=>true,
		'hfnu.check.installed'=>true,
		'banuser.check'=>true,
		),
	'index' => array( 'jacl2.right'=>'hfnu.admin.index'),
	'config'=> array( 'jacl2.right'=>'hfnu.admin.config'),
	'check_upgrade'=> array( 'jacl2.right'=>'hfnu.admin.config')
    );
...
}

Here we specify to 4 plugins coord the action to do :

  • 3 plugins (auth,hfnuinstalled,banuser) for all the actions (by the star '*')
  • 1 plugin (acl2) for 3 actions (index,config,check_upgrade)

little explanation :

  • the 3 first line use the parameter with the value true/false to (de)activate a coordinator
  • the 3 last specify the parameter with as value a 'right' !

If the user access to http://foobar.com/backoffice/action/admin:index, the ACL plugin check the rights 'hfnu.admin.config', which is set, otherwise, displays a message / returns the user.

B) Make his own plugin of Coordinator :

Now that we saw how we used the plugin coord in a controler, let's see how to code one

a coord plugin is composed of 3 files :

  • its config file (optional) : moncoordinateur.coord.ini.php (which will be put in the directory var/config)
  • the coordinator itself : moncoordinateur.coord.php (in the directory plugins/coord/moncoordinateur)
  • plugin.xml : the file defining the plugin itself which is mandatory because of the installation system ;)

Let's have a look to the coordinator which check that it's application is installed, and if not return the user to the installation page or display an error message.

Here the configuration file will allow the webmaster to determine precisely the behavior: display a message or return the the installation page.

Here is an image with the interaction between the Coordinateur, the config file, and the controller :

en/tutorials/plugins/coord/howto.txt · Last modified: 2012/01/31 11:28 by foxmask
Recent changes RSS feed Creative Commons License