模块开发
为开发Dolibarr模块,有以下几个步骤,本向导逐步引导你开发模块,扩展Dolibarr功能。包括以下内容 :
- 在数据库中增加新表
- 增加菜单条目
- 为新表增加新的屏显
- 增删对象的选项卡 (发票、产品、订单、事件,...)
- 为导出工具添加预定义导出
- 在主页增加插件(信息框)
- 添加新的替换变量
- 定义新权限
- 执行由特定Dolibarr动作自动触发的代码
- 将代码插入Dolibarr钩子位置
- 添加编号模块(为数据自动编码的模块)
- 添加文件模板
- 添加新主题
等等...
以上操作,Dolibarr 3.2 版本以上可用。
下面的章节介绍了如何以简单的方式手动完成所有这些操作。对于有经验的开发人员来说,使用MDA生成的方法也不错。 见最后一章。
用ModuleBuilder创建模块
从Dolibarr 7.0.0 开始,可以使用ModuleBuilder创建模块,为激活ModuleBuilder,按以下步骤:
- 设置参数 MAIN_FEATURES_LEVEL 的值为 2 ( 设置 / 其他 )(或者修改llx_const表中该项的记录的value值为2)
- 在主页-设置-模块中激活 ModuleBuilder.
- 点击右上角的‘Bug’图标开始使用(或者在浏览器中输入'yourhost/modulebuilder')
- 运行的ModuleBuilder界面如下:
模块实例
这里可以找到一个启动外部模块开发的好模型:Github Dolibarr模块
创建模块
创建模块主文件 (必需)
何时: 任何模块(除了主题)开始开发之日起。
自Dolibarr 6.0起, 应使用the ModuleBuilder创建标准模块
使用ModuleBuilder创建主模块文件
在下图‘模块名’处填入模块名,然后点击右侧的‘创建’按键,完成创建模块主文件。
- 改变模块ID值: $this->numero = 100000(将此100000变更为你为模块设置的ID值)。为了避免与其他模块发生冲突,您可以查阅列出已保留ID号的页面: List of modules id.
- 修改构造函数中定义的其他变量 (参考主模块代码框架中的注释内容).
您的模块的文件描述符已准备就绪。请参见下一步激活它。
创建模块主文件
创建模块主文件.
- 创建目录 /htdocs/mymodule/core/modules. 从目录/modulebuilder/template/core/modules拷贝文件modMyModule.class.php到新建目录。
将 modMyModule.class.php 改名,名称对应于您的模块。名称以 'mod'开头,以.class.php结尾。 (例如:要创建模块 'NewName', 对应的模块名为'modNewName.class.php'). 接下来修改此文件的内容如下:
- 替换所有 "modMyModule",对应于模块名称。 此值须以'mod'开头且仅含字符 (例如,模块为 'NewName', 替换所有 "modMyModule" 为 "modNewName")。
- 改变模块ID值: $this->numero = 100000(将此100000变更为你为模块设置的ID值)。为了避免与其他模块发生冲突,您可以查阅列出已保留ID号的页面: List of modules id.
- 修改构造函数中定义的其他变量 (参考代码构架中注释的内容).
您的模块的文件描述符已准备就绪。请参见下一步激活它。
测试模块
找到 设置->模块。 如果正确的设置了版本,你会看到模块及模块的激活开关。如果版本设置为了 "develop" 或 "experiental", 则必须到 设置->其他中设置MAIN_FEATURES_LEVEL 为 1 来查看 "experimental"版模块或 2 来查看 "development"版模块。
模块文件路径树(必需)
模块组织文件的方法(zip文件须与此匹配)。
注:只有第二行是强制性的。
- mymodule/* ---------------- 包含php页面(请注意,您也可以添加您选择的任何其他子目录)。注意:如果您的模块是一个metapackage(一个以zip的形式嵌入其他模块的模块),则必须在此处放置一个文件 metapackage.conf。
- mymodule/build/ ----------- 可以包含用于编译或构建模块安装包而开发的任何文件
- mymodule/core/modules/ ---- 包含模块描述符文件 modMyModule.class.php
- mymodule/core/triggers ---- 包含模块提供的触发器
- mymodule/admin/ ----------- 包含设置模块的页面
- mymodule/class/ ----------- 包含模块提供的PHP类文件
- mymodule/css -------------- 包含模块提供的CSS文件
- mymodule/js --------------- 包含模块提供的javascript文件
- mymodule/docs ------------- 提供doc和licence文件
- mymodule/img -------------- 包含模块提供的图片文件
- mymodule/langs/xx_XX ------ 包含xx_XX语言的语言文件(至少要放一个 en_US 语言文件)
- mymodule/lib -------------- 包含模块提供和使用的库文件
- mymodule/scripts ---------- 提供命令行工具或脚本。注意:命令行脚本的第一行必须是:#!/usr/bin/env php
- mymodule/sql -------------- 包含模块提供的用于添加新表或索引的SQL文件
- mymodule/themes/mytheme --- 如果模块提供了自己的主题/皮肤
创建数据表和表的PHP类文件 (可选)
何时: 模块有自己的数据
创建.sql文件
如果你的模块有自己的数据要管理,而Dolibarr的标准版中没有这些数据,就需要自定义数据库表来存储数据。
创建表和加载数据的脚本文件必须放在你的模块目录中创建子目录“sql”中(如htdocs/mymodule/sql)
检查模块主文件,"init"函数中是否包括行:
$this->_load_tables('/mymodule/sql/');
规则:
- 新建表的命令在文件 llx_matable.sql中, 或者还有 llx_matable.key.sql (参见 install/mysql/tables 实例).
- 管理数据:在目录 /mymodule/sql/中创建文件 data.sql 文件中包括增删模改数据的命令。
- 不要使用双引号 (如使用 'chaine' 而不使用 "chaine") 因为双引号有特殊意义(PostGreSQL)。
data.sql实例
delete from llx_const where name='MYMODULE_IT_WORKS' and entity='__ENTITY__';
insert into llx_const (name, value, type, note, visible, entity) values ('MYMODULE_IT_WORKS','1','chaine','A constant vor my module',1,'__ENTITY__');
对于MySQL数据库,文件必须是可操作的。REM:其他数据库的文件不被维护。它们将由另一个数据库的驱动程序进行读取和转换。
测试 .sql 文件
一旦文件准备就绪,您可以返回Dolibarr以禁用该模块,在数据库中将模块使用的表删除,并重新激活模块。应该能通过激活模块来重新创建表。否则,请通过手动传递脚本,或者检查Dolibarr日志。
生成 PHP DAO 类文件
一旦将表创建到数据库中,就转到DEV/Skeleto目录
php build_class_from_table.php tablename modulename
注意:如果命令不工作,尝试使用PHP-CLI PHP代替。 这将生成一个文件out.tablename.class.php,它包含管理表tablename的类。 在这个类中,您可以找到CRUD方法(Create / Read / Update / Delete),在其中进行插入、获取(选择)、更新、删除表中的行。 从文件名中删除“out”,并将文件放在“模块”的子目录中(例如,在htdocs/mymodule/class中)。
已经生成了一个文件out.tablename_script.php,并包含一个示例代码,使用了4个CRUD方法中的每一个。
自从Dolibarr 6.0开,不再提供文件dev/skeletons/build_class_from_table.php。要从一个表生成一个类,您应该使用ModuleBuilder模块。
使用ModuleBuilder生成PHP DAO类文件
- 使用ModuleBuilder生成PHP DAO类文件,简单至在下图中选对'对象'选项卡,输入'对象名',然后点击创建,即可生成相关一切文档。
选项卡管理(可选)
增删对象的选项卡
何时: 增加对象选项卡 (对象是指‘发票’、‘订单’、‘提议’、‘会员’等等)
为此,进入先前创建的模块主文件,并编辑$this->tabs数组:
// Array to add new pages in new tabs or remove existing one
$this->tabs = array('objecttype:+tabname1:Title1:mylangfile@mymodule:$user->rights->mymodule->read:/mymodule/mypagetab1.php?id=__ID__' // To add a new tab identified by code tabname1
'objecttype:+tabname2:Title2:mylangfile@mymodule:$user->rights->mymodule->read:/mymodule/mypagetab2.php?id=__ID__', // To add a new tab identified by code tabname2
'objecttype:-tabname'); // To remove an existing tab identified by code tabname
该数据包含一个字符串列表,每个字符串表示一个新选项卡。 字符串由":"分隔的5个部分组成。
- Part 1: 选项卡出现在的对象类型(objecttype),只能是以下值:
- 'thirdparty' to add a tab in third party view
- 'intervention' to add a tab in intervention view
- 'supplier_order' to add a tab in supplier order view
- 'supplier_invoice' to add a tab in supplier invoice view
- 'invoice' to add a tab in customer invoice view
- 'order' to add a tab in customer order view
- 'product' to add a tab in product view
- 'stock' to add a tab in stock view
- 'propal' to add a tab in propal view
- 'member' to add a tab in fundation member view
- 'contract' to add a tab in contract view
- 'user' to add a tab in user view
- 'group' to add a tab in group view
- 'contact' to add a tab in contact view
- 'payment' to add a tab in payments view (since 3.6.0)
- 'payment_supplier' to add a tab in supplier payments view (since 3.6.0)
- 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
- Part 2: 标识选项卡是添加(以+开始)或移除(以-start)的代码
- Part 3: 选项卡的标题。这可以是lang文件中的译文代码或者是一个直接的字符串。
- Part 4: 文件“*.lang”的名称,包含译文代码和要显示的语言之间的对应关系。如果这个名字跟随 @mymodule,Dolibarr将搜索模块内的翻译文件“*.lang”,即"htdocs/mymodule/langs/code_CODE/mylangfile.lang"。否则Dolibarr将查找文件"htdocs/langs/code_CODE/mylangfile.lang"
- Part 5: 测试选项卡是否必须可见的条件。为1则一直可见。
- Part 6: 单击选项卡时要显示的页面的URL。字符串__ID__将由相关元素的ID自动替换。
要用数据库中的数据来填充选项卡的内容,请参阅下一章。
在你的页上显示选项卡导航
何时: 在页面上显示对象的所有标准选项卡(产品、第三方等)。
你必须遵循这些步骤:
1. 包含文件中需要的文件
对于每个对象类型,有两个文件要包含。
require_once($url_fichier) ;
包含示例 (DOL_DOCUMENT_ROOT 代表 dolibarr/htdocs/) :
- 对象第三方(thirdparty) :
- DOL_DOCUMENT_ROOT/societe/class/societe.class.php
- DOL_DOCUMENT_ROOT/core/lib/company.lib.php
- 对象产品(product) :
- DOL_DOCUMENT_ROOT/product/class/product.class.php
- DOL_DOCUMENT_ROOT/core/lib/product.lib.php
- 对象发票 (invoice) :
- DOL_DOCUMENT_ROOT/compta/facture/class/facture.class.php
- DOL_DOCUMENT_ROOT/core/lib/invoice.lib.php
...
2. 创建并加载对象以显示在您的选项卡中
通过从url(ie : /mytab.php?id=1)获取的id值,使用对象的获取方法,从数据库中创建正确的类和加载对象的实例。
例如:
$id=GETPOST('id','int');
$ref=GETPOST('ref','alpha');
$product = new Product($db) ;
$result = $product->fetch($id,$ref) ; // Test $result to check the database read is ok
3. 为你的对象类型获取所有可显示的选项卡列表
使用函数XXX_prepare_head($obj),其中XXX是对象的名称。这将返回一个数组,包含所有选项卡条目的定义。要放入该方法的参数是要显示选项卡的对象实例。
返回的数组为:
$head // Array of tabs
$head[$h] // Element to describe one tab.
$head[$h][0] // Url of page to show when you click on tab
$head[$h][1] // Title of tab
$head[$h][2] // Code name to identify the tab
例如 :
$head = product_prepare_head($product, $user) ; // 参数 $user 是要显示选项卡的对象,这就是"产品"对象为"user"对象准备的所有可用的选项卡的数组。
4. 在你的页面上显示选项卡
使用函数dol_fiche_head()显示由函数XX_prepare_head()返回的$head数组定义的定义的所有选项卡。
dol_fiche_head($links, $active='0', $title='', $notab=0, $picto='')
//$links // Tableau des onglets, appelé $head plus haut.
//$active // Onglet actif (mettre le nom de l'onglet défini dans votre fichier de module, ou un nom contenu dans $head[$h][2]). Cet onglet sera mis en surbrillance
//$title // Title to show (shown into a special tab that you can't click)
//$notab
//$picto // Name of image to show into title. Possible values are:
// product
// service
// company
This function will show required tabs and open an html element < div class="" > that correspond to the area under the tabs. To close area of a tab, just use < /div > into your PHP page.
创建或修改 PHP 屏显 (可选)
何时: 如果模块的目的是为了修改屏显。
创建新 PHP 屏显
然后,您必须创建PHP页面,使用目录modulebuilder/myobject_page.php中提供的框架模板来显示/编辑表中的数据。 (从命令行开发脚本, 见 Script development).
要创建一个新的用户屏幕,创建一个模块名的子目录(若无) (例如 htdocs/mymodule) 来存储创建的屏幕。
复制 myobject_page.php 做为屏幕页。
编辑该文件,以包括正确的 main.inc.php文件。
// Load Dolibarr environment
$res=0;
// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
if (! $res && ! empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) $res=@include($_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php");
// Try main.inc.php into web root detected using web root caluclated from SCRIPT_FILENAME
$tmp=empty($_SERVER['SCRIPT_FILENAME'])?'':$_SERVER['SCRIPT_FILENAME'];$tmp2=realpath(__FILE__); $i=strlen($tmp)-1; $j=strlen($tmp2)-1;
while($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i]==$tmp2[$j]) { $i--; $j--; }
if (! $res && $i > 0 && file_exists(substr($tmp, 0, ($i+1))."/main.inc.php")) $res=@include(substr($tmp, 0, ($i+1))."/main.inc.php");
if (! $res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i+1)))."/main.inc.php")) $res=@include(dirname(substr($tmp, 0, ($i+1)))."/main.inc.php");
// Try main.inc.php using relative path
if (! $res && file_exists("../main.inc.php")) $res=@include("../main.inc.php");
if (! $res && file_exists("../../main.inc.php")) $res=@include("../../main.inc.php");
if (! $res && file_exists("../../../main.inc.php")) $res=@include("../../../main.inc.php");
if (! $res) die("Include of main fails");
注: that you may add more "../" depending on the depth of the file relative to your module directory tree. The modules developed for all version of Dolibarr after the 3.2 should be able to be moved in a different folder than "htdocs", like "htdocs/custom", without having to modify the source code of the module, that's why we make several includes, so this rule must be applied by all modules.
It's in the main.inc.php file that is loaded technical environment variables and permissions. The following variables are objects positioned in this file:
- $user Objet that contains the characteristics of the user + his permissions.
- $conf Objet that contains Dolibarr configuration.
- $db Objet that contains an opened connection handler to the database.
- $langs Objet that contains the user's language.
Then enter your code to display the page.
- To include a class or library dedicated to the module is done using a Dolibarr function (and not using directly include_once):
Example :
dol_include_once('/mymodule/class/myclass.class.php', 'MyClass');
- To include classes provided with Dolibarr, use the following syntax:
Example :
require_once DOL_DOCUMENT_ROOT.'/core/class/doli.class.php';
为现存表单增加新字段
You may want to provide a module that add more fields into forms (input and view) of some elements.
A heavy solution (but not so bad) may be to replace all pages used to create element (this means disable the "New element" menu entry and adding yours, and disable tab that show element to replace with a tab that is your own full page (copied/pasted from original) to do same than original page but modified to add your fields and stored added data into your own table). Go to menu #Define your entries in menu (optional) and #The tab management (optional) if this solution suits you (this solution is more powerfull since you can change everything you want into page).
We will describe here another solution, that works only to "add fields" at end of existing fields, using the element "category" as an example but you can convert this tutorial for invoice, proposal ...
- First thing is to add a table, owned by your module, to store value of new fields. This table will have only one column called "rowid" (will contains same value than field rowid of element table) + one column for each new field you want to add. Then create a class with CRUD (Create/Read/Update/Delete) methods for this new table. For this two tasks, go back to previous chapter #Create your SQL tables and the PHP DAO class.
- Next step is to add a hook into your module to add the new fields into the form. See chapter Hooks_system#Implement_the_Hook for generic documentation to use hooks.
If you follow this tutorial, to be able to add fields into category forms, you must do:
替换模板的部分内容 (version 3.3+)
Some parts of Dolibarr screen are isolated into native PHP template files. You can develop a module to overwrite such templates with yours.
增/换部分字段(需钩子支持)
See chapter Hooks_system#Implement_the_Hook to know how to use Dolibarr existing hooks to add/replace code at Dolibarr hooks place.
数据通道
If you need to edit some data in database inside you own table, use the PHP class generated before.
If you to make access to tables with no dedicated PHP class available, this is always possible (for example if you want to get a list of records with a particular join or filter). In this case, this is a code samples to follow:
To make an insert, update or delete:
$db->begin(); // Start transaction
$db->query("My SQL request insert, update or delete");
$db->commit(); // Validate transaction
or $db->rollback() // Cancel transaction
To read:
$resql=$db->query("My select request");
if ($resql)
{
$num = $db->num_rows($resql);
$i = 0;
if ($num)
{
while ($i < $num)
{
$obj = $db->fetch_object($resql);
if ($obj)
{
// You can use here results
print $obj->field1;
print $obj->field2;
}
$i++;
}
}
}
页面风格
To have the look of your own pages to match the Dolibarr theme, it is necessary to use the Dolibarr CSS styles.
You can use for example:
- class="liste_titre" on tags tr and td for the head row of a table.
- class="pair" or class="impair" on tags tr and td of other rows of a table.
- class="flat" on all input fields (input, select, textarea...).
- class="button" on HTML fields with type input type="submit".
使用Dolibarr日期选择器
If you want to use the Dolibarr date selector (with its calendar popup) into your pages, use the following line:
$form=new Form($db);
$form->select_date('','mykey',0,0,0,"myform");
The string mykey will identify the date selector in the form. You must use different values if you use several date selectors in same page. The string myform is the name of the FORM in which the selector is included (value found in the form name="myform" in HTML page). This means a date selector must be included necessarily into an html FORM.
To get value after the POST of your form, the command is:
$mydate = dol_mktime(12, 0 , 0, $_POST['mykeymonth'], $_POST['mykeyday'], $_POST['mykeyyear']);
print strftime('%A %d %B %Y', $mydate);
新增设置页 (可选)
When: If your module needs parameters, which are to be provided by the user, for proper setting up of the module.
创建页面以编辑参数
If your module needs several parameters to be setup, you must create a page to edit options (these options will be saved in the table llx_const). Create a page named mymodule_setuppage.php that shows a form for possible options to update them into the above mentioned table. It is necessary to take an example from a page of the directory /admin that will show you the way to read/save your parameters. Put this PHP page into the directory /admin of your module (e.g. mymodule/admin/mymodule_setuppage.php).
修改模块主文件
Then, within the descriptor file of your module, modify the variable config_page_url to set name of this PHP page. If the page is in the directory admin/, then the path is not required, e.g. like this:
$this->config_page_url = array("mymodule_setuppage.php");
If the page is in the directory mymodule/admin/, then like this:
$this->config_page_url = array("mymodule_setuppage.php@mymodule");
测试页面
Go into page Home->Setup->Modules, you should see a picture at the end of the line of your module to reach your setup page. Click on it, you should be able to view/edit parameters from your page.
增加菜单条目 (可选)
When: If you have created PHP pages, it is necessary that those pages can be reached from menu entries in Dolibarr menu.
增加菜单条目
For this, you must define into the module descriptor, the array this->menu that declare all menus added by your module. This array contains entries that will appear once your module is activated. The example module descriptor file modMyModule.class.php contains an example to declare a top menu and also its left menu entries.
This is the example of code to declare your own menu entries in a module descriptor file:
// Main menu entries
$this->menu = array(); // List of menus to add
$r=0;
// Add here entries to declare new menus
// Example to declare the Top Menu entry:
$this->menu[$r]=array( 'fk_menu'=>0, // Put 0 if this is a top menu
'type'=>'top', // This is a Top menu entry
'titre'=>'MyModule top menu',
'mainmenu'=>'mymodule',
'leftmenu'=>'mymodule',
'url'=>'/mymodule/pagetop.php',
'langs'=>'mylangfile', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
'position'=>100,
'enabled'=>'1', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled.
'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
'target'=>'',
'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
$r++;
// Example to declare a Left Menu entry:
$this->menu[$r]=array( 'fk_menu'=>'fk_mainmenu=xxx', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode of parent menu
'type'=>'left', // This is a Left menu entry
'titre'=>'MyModule left menu 1',
'mainmenu'=>'xxx',
'leftmenu'=>'yyy',
'url'=>'/mymodule/pagelevel1.php',
'langs'=>'mylangfile', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
'position'=>100,
'enabled'=>'1', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled.
'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
'target'=>'',
'user'=>2); // 0=Menu for internal users,1=external users, 2=both
$r++;
To show menu or not depending on a permission, modify property perms in array. See chapter on permissions later to see how to add permissions.
测试菜单
Disable and reenable your module under Dolibarr module setup page, menus entries must appear (if property 'enabled' is declaration array is ok).
新增权限 (可选)
When: If you want to add new permissions.
The way to define permissions that will manage your module is done inside the module descriptor created previously. Modify line
$this->rights_class = 'mymodule'
with correct value for mymodule.
Then you must fill the array $this->rights with as many entries than different permissions you need to manage.
$this->rights[$r][0] = 10001;
$this->rights[$r][1] = 'Label by default of permission';
$this->rights[$r][3] = 1;
$this->rights[$r][4] = 'action';
$this->rights[$r][5] = 'subaction';
$r++;
Into $this->rights[$r][0], put a permission id not already used (See into menu System info on a working installation of Dolibarr to know list of id already used by standard modules. Into $this->rights[$r][3], put 1 if this permission must be granted automatically by default to any new created user. Into $this->rights[$r][1], put a label by default for permission (This label will be used if no translation can be found into the file admin.lang). Into $this->rights[$r][4] and $this->rights[$r][5], put an action and subaction string without spaces. You will be able to test if a user has the permission in your PHP source code with the sequence:
if ($user->rights->mymodule->action->subaction) ...
信息窗 (可选)
When: If your module need to provide one or several new boxes to show on home page.
信息窗
For this, modify the array $this->boxes into the module descriptor file. All you have to do is to add 2 lines for each box file you will create into directory htdocs/mymodule/core/boxes
Example:
$this->boxes[0]['file']='mybox0.php@mymodule'
$this->boxes[0]['note']='My box 0'
...
$this->boxes[n]['file']='myboxn.php@mymodule'
$this->boxes[n]['note']='My box n'
Then create files htdocs/mymodule/core/boxes/mybox0.php, htdocs/mymodule/core/boxes/mybox1.php... by copying an example from an existing box file (found into directory htdocs/core/boxes).
Test if your box is detected by Dolibarr
Disable and enabled module.
Go into menu Home - Setup - Boxes.
Your boxes must appear in the list of boxes you can activated. Activate the box and go on home page to see if the box is showing correctly.
Define your own export (optional)
When: If your module provide new predefined database export profiles (for its own tables or for already existing tables of another module).
导出
For this uncomment and modify arrays $this->export_xxx in your module descriptor file.
Test your export
Go into menu Tools -> Export. Your export will appear in the list of available predefined exports (if your module is enabled). Choose it, you must see list of all possible fields defined in the export arrays. Choose on field and try to build an export file. If ok, try again with all fields.
Define your CSS styles (optional)
When: If in your PHP pages, you use class styles that are not defined inside Dolibarr themes CSS (not recommanded).
Create and declare your style sheet
Create a style sheet CSS named mymodule.css or mymodule.css.php and put it into directory htdocs/mymodule. You can have only one CSS file per module. Remember it's better to use existing styles already available by default into Dolibarr (The CSS file used by Dolibarr is file themes/mytheme/themename.css.php. Create your own CSS file only if you need absolutely to add not already existing styles.
Once your style sheet is ready, declare it into your module descriptor file by modifying the property $this->modules_parts. Value to put here must be a relative URL to your CSS file. For example
$this->module_parts = array('css' => array('/mymodule/css/mymodule.css.php'));
Test your style sheet
Disable and enable your module.
Go on home page (index.php). Show the HTML source of the page.
You should see into the HTML header, a line that declare your style sheet.
增加JS函数功能 (可选)
When: If in your PHP pages, you use javascript functions not available in Dolibarr (in file lib_head.js)
If you need to use your own javascript functions inside your PHP pages, it is necessary to have your functions, defined into your javascript file htdocs/mymodule/js/mymodule.js, included into the HTML HEAD section. To ask Dolibarr that forge this header to include your own javascript file, you must just provide it to the llxHeader() function called by your page.
Example for page /htdocs/mymodule/mypage.php :
$morejs=array("/mymodule/js/mymodule.js");
llxHeader('','Titre','','','','',$morejs,'',0,0);
执行Dolibarr事件代码 (可选)
When: If you want to execute your own code once a common Dolibarr event has occurred (example: I want to update a table in my module when an invoice is created into Dolibarr), you must create a triggers.
See also Interfaces_Dolibarr_toward_foreign_systems and Interfaces_from_foreign_systems_toward_Dolibarr
钩子代码 (可选)
When: When you want to add code or replace Dolibarr code into another situation than a business event (See previous chapter for adding code during a business event).
See page Hooks_system.
添加编码规则
When: When you need a new rule for generated ref of elements that is not covered by existing rules.
See page Create numbering module.
创建文档模板 (optional)
When: When you want to personalized your own generated PDF or ODT documents.
Note: To add this feature you don't need to create a module descriptor.
Documentation to add your own template is available on page Create_a_PDF_document_template or Create_an_ODT_document_template.
创建主题 (optional)
When: When you want to personalized your colors/fonts/images.
Note: To add this feature you don't need to create a module descriptor.
To add your own skin, read page Skins.
一些编码规则和预定义函数
The coding rules to be followed are defined in the Developer documentation, under section "General Information - Language and standards development".
A lot of predefined features for developers are also available and described into page Developer documentation under section "Technical components of Dolibarr".
使用 MDA
A method to generate a functional module from a UML model has been developed. More information on the page UML2Dolibarr - Build a module using MDA.
创建一个安装包来分发和安装您的模块
This process must be used to generate a package to submit it on the http://www.dolistore.com market place. But you can use it to have a package easy to distribute on your on network.
- Go into the directory /build and copy the file makepack-dolibarrmodules.conf into makepack-mymodule.conf. Warning, this directory may not be provided in some packages of stable versions. If so, it can be retrieved from the snapshot available for download on the Dolibarr website in area "Development version" (taken in this case the whole build directory which is autonomous and independent directory).
Edit this file to add list of file names for all new files you created for your module (module descriptor, new sql tables files, php page, images, etc...)
- Run the script via Perl (need the Perl version 5.0 or later):
perl makepack-dolibarrmodule.pl
The script asks you the name of your module, its major and minor version. A file mymodule.zip will then be manufactured containing your module ready to be deployed.
- The person who receives your module must then place the file in the root directory of a Dolibarr installation and perform the command:
tar -xvf mymodule.zip
- If you want your module to be public, you can submit it (the zip file) on Dolibarr market place web site: DoliStore.com (you must create an account first and be logged to use the link "Submit a module/product").
- If your module was build correctly, file will be validated later.
- If quality is enough and license permits it, code might be added inside main Dolibarr sources (except if you disagree for that).
Delistor上的外部模块的启用/激活条件
See Validation Rules
