模块开发
为开发Dolibarr模块,有以下几个步骤,本向导逐步引导你开发模块,扩展Dolibarr功能。包括以下内容 :
- 在数据库中增加新表
- 增加菜单条目
- 为新表增加新的屏显
- 增删对象的选项卡 (发票、产品、订单、事件,...)
- 为导出工具添加预定义导出
- 在主页增加插件(信息框)
- 添加新的替换变量
- 定义新权限
- 执行由特定Dolibarr动作自动触发的代码
- 将代码插入Dolibarr钩子位置
- 添加编号模块(为数据自动编码的模块)
- 添加文件模板
- 添加新主题
等等...
下面的章节介绍了如何以简单的方式手动完成所有这些操作。对于有经验的开发人员来说,使用MDA生成的方法也不错。 见最后一章。
模块实例
这里可以找到一个启动外部模块开发的好模型:Github Dolibarr模块
创建模块
激活ModuleBuilder模块
从Dolibarr 6.0.0 开始,可以使用ModuleBuilder创建模块,为激活ModuleBuilder,按以下步骤:
- 设置参数 MAIN_FEATURES_LEVEL 的值为 2 ( 设置 / 其他 )(或者修改llx_const表中该项的记录的value值为2)
- 在主页-设置-模块中激活 ModuleBuilder.
- 点击右上角的'Bug'图标开始使用(或者在浏览器中输入'yourhost/modulebuilder')
- 运行的ModuleBuilder界面如下:
创建模块类 (必需)
何时: 任何模块(除了主题)开始开发之日起。
自Dolibarr 6.0起, 应使用ModuleBuilder创建模块类
用ModuleBuilder创建模块类 (新,Dolibarr v6.0起)
在下图'模块名'处填入模块名,然后点击右侧的'创建'按键,创建模块类。
- 改变模块ID值: $this->numero = 100000(将此100000变更为你为模块设置的ID值)。为了避免与其他模块发生冲突,您可以查阅列出已保留ID号的页面: 模块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/build/ 包含用于编译或构建模块安装包的任何文件
- mymodule/core/modules/ 包含模块主文件 modMyModule.class.php
- mymodule/core/triggers 包含触发器
- mymodule/admin/ 包含模块设置页面
- mymodule/class/ 包含 PHP类文件
- mymodule/css 包含 CSS 文件
- mymodule/docs 提供文件和许可文件
- mymodule/img 包含图片文件
- mymodule/langs/xx_XX 包含语言文件 xx_XX (至少放一个 en_US 语言文件)
- mymodule/lib 包含模块需要引用的库文件
- mymodule/scripts 提供命令行工具
- mymodule/sql 包含SQL文件,用以新建数据表或索引
- mymodule/themes/mytheme 如果模块包含主题
- mymodule/* 包含php屏显页 (注意,您还可以在此添加其他子目录。)
创建数据表和表的PHP类文件 (可选)
何时: 模块有自己的数据
创建.sql文件
如果你的模块有自己的数据要管理,而Dolibarr的标准版中没有这些数据,就需要自定义数据库表来存储数据。
创建表和加载数据的脚本文件必须放在你的模块目录中创建子目录“sql”中(如htdocs/mymodule/sql)
检查模块主文件,"init"函数中是否包括行:
$this->_load_tables('/mymodule/sql/');
规则:
- 新建表的命令在文件 llx_mytable.sql中, 或者还有 llx_mytable.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
该数据包含一个字符串列表,每个字符串表示一个新选项卡。 字符串由":"分隔的6个部分组成。
- 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");
注: 你可能增加更多的 "../" 根据你的模块目录的深度。 在3.2之后,为所有版本的Dolibarr开发的模块应该能够在不同的文件夹中移动,而不是“htdocs”,比如“htdocs/custom”,而不必修改模块的源代码,这就是为什么我们要做几个包含,所以这个规则必须被所有模块应用。
在main.inc.php文件中,加载了技术环境变量和权限。以下变量是位于该文件中的对象:
- $user 包含用户+ 权限。
- $conf 包含 Dolibarr 设置
- $db 它包含一个打开的数据库连接处理程序。
- $langs 包含用户语言
然后输入代码显示页面。
- 包含模块专属的类或库,使用Dolibarr函数dol_include_once()(而不是直接使用 include_once):
例如 :
dol_include_once('/mymodule/class/myclass.class.php', 'MyClass');
- 若要包含Dolibarr提供的类,请使用以下语法:
例如 :
require_once DOL_DOCUMENT_ROOT.'/core/class/doli.class.php';
为现存表单增加新字段
您可能需要提供一个模块,该模块将更多字段添加到一些元素的表单(输入和查看)中。
一个较累的解决方案(但不是很糟糕)是替换所有用于创建元素的页面(这意味着禁用“新元素”菜单条目并添加您的,禁用“显示”元素,用一个选项卡替换该元素,该选项卡是您自己的完整页面(从原始复制/粘贴),以完成与原始页面相同的操作,修改以添加字段并将添加的数据存储到自己的表中)。
转到菜单 #Define your entries in menu (optional)和#The tab management (optional),如果这个解决方案适合你(这个解决方案是更强大的,因为你可以改变你想要的一切进入页面)。
我们将在这里描述另一种解决方案,它只在现有字段结束时“添加字段”,使用元素“category”作为示例,但您可以将此教程转换为发票、提案…
- 首先,添加一个由您的模块所拥有的表,以存储新字段的值。此表有一个名为“rowid”的列(将包含与元素表的字段rowid相同的值+每一个要添加的新字段的列。然后为这个新表创建一个CRUD(创建/读取/更新/删除)方法类。对于这两个任务,请回到前一章#创建数据表和表的PHP类文件 (可选)。
- 下一步是在模块中添加一个钩子,以将新字段添加到窗体中。有关使用钩子的通用文档,请参见Hooks_system#Implement_the_Hook章节。
如果您遵循本教程,以便能够将字段添加到类别窗体中,您必须这样做:
增/换部分字段(需钩子支持)
要知道如何使用Dolibarr现有的钩子来添加/替换Dolibarr 钩子代码,参考 钩子系统#实现钩子 。
数据通道
如果需要在自己的表中编辑数据库中的一些数据,请使用的PHP类。
如果您要访问没有专用PHP类的表(例如,如果您想获得具有特定连接或筛选器的记录列表)。在这种情况下,这是要遵循的代码示例:
进行插入、更新或删除:
$db->begin(); // Start transaction
$db->query("My SQL request insert, update or delete");
$db->commit(); // Validate transaction
or $db->rollback() // Cancel transaction
读:
$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++;
}
}
}
页面风格
为了让你自己的页面看起来与Dolibarr主题相匹配,必须使用Dolibarr CSS样式。
例如,您可以使用:
- 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日期选择器
如果您的页面使用Dolibarr日期选择器(日历弹出),请使用以下行:
$form=new Form($db);
$form->select_date('','mykey',0,0,0,"myform");
字符串mykey将标识表单中的日期选择器。如果在同一页中使用多个日期选择器,则必须使用不同的值。
字符串myform是包含选择器的表单的名称(在HTML页面中的form name="myform")中找到的值。
这意味着日期选择器必须包含在HTML表单中。
要获得表单POST的值,命令是:
$mydate = dol_mktime(12, 0 , 0, $_POST['mykeymonth'], $_POST['mykeyday'], $_POST['mykeyyear']);
print strftime('%A %d %B %Y', $mydate);
新增设置页 (可选)
何时: 如果模块需要用户提供的参数,以正确设置模块。
创建页面以编辑参数
如果模块需要设置几个参数,则必须创建一个页面来编辑选项。 (这些制作存储于 表 llx_const).
新建 mymodule_setuppage.php 这显示了可能的选项的表单,将它们更新到上面提到的表中。
有必要从目录/admin 的页面中获取一个示例,它将向您展示读取/保存参数的方法。
把这个PHP页面放到你的模块的/admin (例如mymodule/admin/mymodule_setuppage.php)的目录中。
修改模块主文件
然后,在模块主文件中,将变量“config_page_url”修改为PHP页面的设置名称。
如果页面位于目录admin/中,则不需要路径,例如:
$this->config_page_url = array("mymodule_setuppage.php");
如果页面在目录 mymodule/admin/中,则像这样:
$this->config_page_url = array("mymodule_setuppage.php@mymodule");
测试页面
进入首页->安装>模块,您应该在您的模块行的末尾看到一个图片,以转到您的设置页面。点击它,你就可以从页面中查看/编辑参数。
增加菜单条目 (可选)
何时: 如果您创建了PHP页面,则必须从Dolibarr菜单中的菜单条目中访问这些页面。
增加菜单条目
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.
修改开发模块作者名
在myModule.class.php中查找editor_name
修改以下变量的值以修改作者名称
$this->editor_name = 'Roger@QQ:12464313';
$this->editor_url = 'https://www.ivnun.cn';
一些编码规则和预定义函数
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".
创建一个安装包来分发和安装您的模块
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).
Dolistor上的外部模块的启用/激活条件
See Validation Rules