模塊開發
為開發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_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章節。
如果您遵循本教程,以便能夠將字段添加到類別窗體中,您必須這樣做:
替換模板的部分內容 (version 3.3+)
Dolibarr屏幕的一些部分被隔離到本地PHP模板文件中。 您可以開發一個模塊來覆蓋這樣的模板。
增/換部分字段(需鈎子支持)
要知道如何使用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".
使用 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