Chapter: Developping plugins
« Overloading module files | ^ Advanced development | Dive into configuration » |
− Table of content
Different types of plugins exists for Jelix. Each categories modify or add functionality to differents parts of Jelix. There are coordinator plugins, jDb drivers, jAuth drivers, jTpl plugins...
All plugins are located in plugins repositories.
Adding a plugins repository ¶
You can add one or more plugins repositories. It is a directory with a strict subtree structure.
Each plugins repository must be declared with jApp
or in the composer.json file
(in previous version, it was in the pluginsPath
parameter in the configuration).
Here is an example with jApp
, into application.init.php
:
jApp::declarePluginsDir(__DIR__.'/plugins/');
Here the plugins directory of the application.
Some directories are declared automatically. This is the case of lib/jelix/plugins/
.
it contains all plugins bundled with Jelix. It also loads all plugins/
directories
found into modules.
If you install some packages for Jelix with Composer, plugins directories can be declared automatically by specifying them into the composer.json file of the packages.
{
...
"extra" : {
"jelix": {
"plugins-dir" : [
"plugins/",
]
}
}
}
Here, this composer.json file declare the plugins/
which is in the
same directory of composer.json.
It works also with the composer.json of the application.
Repository structure and plugins creation ¶
A plugins repository has one sub-directory for each plugin type. And within each sub-directory, each plugin has its own folder.
Below is the list of some plugins type and their respective directory:
- coordinator plugins:
coord/
- plugins for jLog:
logger/
- jAuth drivers:
auth/
- jAcl2 drivers:
acl2/
- jDb drivers:
db/
- jDao drivers:
daobuilder/
- templates plugins:
tpl/
- jForms generators:
jforms/
- jKVDb drivers:
kvdb/
- jCache drivers:
cache/
- plugins for the debugbar:
debugbar/
- plugins for jResponseHtml:
htmlresponse/
- plugins for jProfiles:
profiles/
Plugins loading ¶
Components which are using plugins, load them with the method jApp::loadPlugin()
.
You could need it too to load a plugin, in order to retrieve its configuration or to use it.
To instancy it, you have several parameters. Th first is the plugin name, then, the plugin type ('db', 'acl'...), the suffix of the file name ('.dbconnection.php'..), the class name ('mysqliDbConnection') and the last one: a parameter for the constructor.
$plugin = jApp::loadPlugin('mysqli'', 'db', '.dbconnection.php', 'mysqliDbConnection', 'default');
You see that there is a limitation: you cannot give several parameters to the constructor.
You could then simply load the plugin with jApp::includePlugin()
, and instancying
it yourself. This method has same parameters as loadPlugin()
, without the parameter
for the constructor of course.
jApp::includePlugin('mysqli'', 'db', '.dbconnection.php', 'mysqliDbConnection');
$plugin = new mysqliDbConnection('default');
Plugins development ¶
Jelix comes with a bunch of plugins within the standard package. They are located in
lib/jelix/plugins/
. However, it is often useful to create your own plugins to
fulfill specific needs. And If your plugin is generic or useful enough, you're likely to
push it to the developers team :-).