8
edits
Tag: 2017 source edit |
m (Fix some language mistakes, improve some style) Tag: 2017 source edit |
||
| Line 12: | Line 12: | ||
{{TemplateDocDevEn}} | {{TemplateDocDevEn}} | ||
To create a new module/addon for Dolibarr, there | To create a new module/addon for Dolibarr, there are several steps. This tutorial will describe each of them to let you build a module that extends Dolibarr features, such as: | ||
*Add new tables in database. | *Add new tables in database. | ||
| Line 30: | Line 30: | ||
etc... | etc... | ||
The following chapters explain how to do all of this manually in an easy way. | |||
=Module creation with the module builder= | =Module creation with the module builder= | ||
From Dolibarr v. 12.0 it is possible to create the main pages of your module with the Module Builder. To activate it: | From Dolibarr v. 12.0 it is possible to create the main pages of your module with the Module Builder. To activate it: | ||
Go into the list of | Go into the list of modules and enable the "Module Builder" module: | ||
[[File:Module Builder.png|alt=Module Builder|thumb|none]] | |||
| Line 41: | Line 42: | ||
<br /> | <br /> | ||
=Template of an External Module= | =Template of an External Module= | ||
A good model to start development of external module can be found here : [https://github.com/Dolibarr/dolibarr/tree/develop/htdocs/modulebuilder/template GitHub Dolibarr Module | A good model to start development of external module can be found here : [https://github.com/Dolibarr/dolibarr/tree/develop/htdocs/modulebuilder/template GitHub Dolibarr Module Template] | ||
=Create your module= | =Create your module= | ||
| Line 52: | Line 53: | ||
The first step is to create a file descriptor for the module. | The first step is to create a file descriptor for the module. | ||
*Create directory '''/htdocs/custom/''mymodule''/core/modules''' (for an external module) or '''/htdocs/''mymodule''/core/modules''' if you plan to have this module an official core module of Dolibarr. Then copy the file modMyModule.class.php from the directory '''htdocs/modulebuilder/template''' into this directory. Change the name of the file modMyModule.class.php to the name corresponding to the purpose of your module. Name of the file must start with | *Create directory '''/htdocs/custom/''mymodule''/core/modules''' (for an external module) or '''/htdocs/''mymodule''/core/modules''' if you plan to have this module an official core module of Dolibarr. Then copy the file <code>modMyModule.class.php</code> from the directory '''htdocs/modulebuilder/template''' into this directory. Change the name of the file <code>modMyModule.class.php</code> to the name corresponding to the purpose of your module. Name of the file must start with <code>mod</code> and end with <code>.class.php</code> (for example if you want to give the name 'NewName' to this file, then the name should be <code>modNewName.class.php</code>). | ||
Then, modify the contents of this file as follows: | |||
*Replace all "modMyModule" with a value which corresponds to the purpose of your module. This value must always start with 'mod' and contain only alpha characters (again, if the name given to the file was 'NewName', then replace all "modMyModule" with "modNewName"). | *Replace all occurrences of "modMyModule" with a value which corresponds to the purpose of your module. This value must always start with 'mod' and contain only alpha characters (again, if the name given to the file was 'NewName', then replace all "modMyModule" with "modNewName"). | ||
*Change the number in: $this->numero = 100000 by a number that designates your module id. To avoid conflicts with other modules, you can consult the page that lists already reserved id numbers: [[List of modules id|List of modules id]]. | *Change the number in: $this->numero = 100000 by a number that designates your module id. To avoid conflicts with other modules, you can consult the page that lists already reserved id numbers: [[List of modules id|List of modules id]]. | ||
*Modify any other variables defined in the constructor (see comment in the code skeleton for their meaning). | *Modify any other variables defined in the constructor (see comment in the code skeleton for their meaning). | ||
| Line 100: | Line 101: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Files must be operational for the database mysql. | Files must be operational for the database mysql. Note: The files of other databases are not maintained. They will be read and converted on the fly by the driver of the other database. | ||
===Test your .sql files=== | ===Test your .sql files=== | ||
Once the files ready, you can return to the page to enable Dolibarr modules and disable the module, drop those tables in the database (if they already | Once the files ready, you can return to the page to enable Dolibarr modules and disable the module, drop those tables in the database (if they already exist) and reactivate the module. The tables should be recreated by the activation of the module. If this is not the case, check your scripts by passing them by hand, or check the Dolibarr logs. | ||
===Generate the PHP DAO class=== | ===Generate the PHP DAO class=== | ||
edits