Section: Creating a module
|^ Developing a module||Developing a controller »|
− Table of content
A module is a directory in which there are classes and files related to a domain. This files are organised in a precise file-system hierarchy as indicated below.
Creating a module ¶
It's as simple as creating a sub-directory of a modules group, and filling it with controllers, persistent objects ...
Of course the module group should have been created and declared.
module:create command helps you to create all directories of a module,
and it activates and installs automatically the new module:
php dev.php module:create mymodule
This command creates the module "mymodule" in your application's sub-directory
modules. It creates also some sub-directories as well as a default
Important: The name of modules are used in the name of some classes
generated automatically by Jelix. So you mustn't use other characters than a-z,
A-Z, 0-9 and
By default, the module is created in the
modules/ directory of the
application. Perhaps you would like to create it into an other modules group. In
this case, indicate the path of the repository after the module name.
This example creates a "supermodule" module into the
directory which is itself into the
lib directory provided with jelix.
php dev.php module:create supermodule ../lib/shared-modules/
See the online help of the
module:create command to know other options.
Setting the version and dependencies ¶
After creating the module, you should verify if the default initial version is ok for you (0.1), and set dependencies. It is very important for the installation system of Jelix.
You can indicate the version to the
module:create command, with the
php dev.php module:create --ver 1.0 supermodule
You can also modify the version in the
module.xml file generated in the module, if needed.
You can set dependencies of the module. Dependencies are modules necessary to
execute the new module. In the
<dependencies> element in the
module.xml file, add a
<module> element for each required module.
<dependencies> <jelix minversion="1.6.0" maxversion="1.6.*" /> <module name="jauth" minversion="1.2" /> <module name="anOtherModule" minversion="1.0" maxversion="1.4.*" /> </dependencies>
maxversion are optional.
For more details about the content of module.xml, read the corresponding chapter.
Directories inside a module ¶
A module is a directory having at least one file, module.xml, containing some informations about the module: version, dependencies...
And you have some sub-directories, depending of what the module provides, and each containing specific files:
- controllers, corresponding to some URL
- business classes, librairies, listeners for events etc.
- file containing the content to send to browsers
- response object that the module can provide for the whole application
- properties files to localize templates or content generated by controllers
- classes generating some part of a web page
- files declaring mapping to a database
- file declaring forms
- scripts to install or to upgrade the module
- scripts for the command line
- plugins for various components (jDb, jTpl...)
- CSS, JS, images files. There are accessible from a browser, by calling a specific controller of the "jelix" module
- files doing unit tests for PHPUnit