模块开发: Difference between revisions

Tag: 2017 source edit
 
(8 intermediate revisions by the same user not shown)
Line 11: Line 11:


[[Category:Core]]
[[Category:Core]]
[[Category:开发]]
{{Template用户手册}}
{{Template用户手册}}
{{Template开发文档}}
{{Template开发文档}}
Line 171: Line 172:


<syntaxhighlight lang="PHP">
<syntaxhighlight lang="PHP">
// Array to add new pages in new tabs or remove existing one
// 用于在新tabs中添加新页面或删除现有页面的数组
$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
$this->tabs = array('objecttype:+tabname1:Title1:mylangfile@mymodule:$user->rights->mymodule->read:/mymodule/mypagetab1.php?id=__ID__'    // 增加一个由code tabname1标识的新tab
                             'objecttype:+tabname2:Title2:mylangfile@mymodule:$user->rights->mymodule->read:/mymodule/mypagetab2.php?id=__ID__',  // To add a new tab identified by code tabname2
                             'objecttype:+tabname2:Title2:mylangfile@mymodule:$user->rights->mymodule->read:/mymodule/mypagetab2.php?id=__ID__',  // 增加一个由code tabname2标识的新tab
                             'objecttype:-tabname');                                                    // To remove an existing tab identified by code tabname
                             'objecttype:-tabname');                                                    // 删除一个由code tabname标识的现有选项卡
</syntaxhighlight>
</syntaxhighlight>


Line 239: Line 240:


<syntaxhighlight lang="PHP">
<syntaxhighlight lang="PHP">
$head        // Array of tabs
$head        // tabs的数组
$head[$h]    // Element to describe one tab.
$head[$h]    // Element to describe one tab.
$head[$h][0] // Url of page to show when you click on tab
$head[$h][0] // Url of page to show when you click on tab
Line 260: Line 261:
<syntaxhighlight lang="PHP">
<syntaxhighlight lang="PHP">
dol_fiche_head($links, $active='0', $title='', $notab=0, $picto='')
dol_fiche_head($links, $active='0', $title='', $notab=0, $picto='')
//$links  // Tableau des onglets, appelé $head plus haut.
//$links  // tabs的数组,上面称为$head
//$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
//$active // 活动选项卡(输入模块文件中定义的选项卡名称,或$head[$h][2]中包含的名称)。此选项卡将突出显示
//$title  // Title to show (shown into a special tab that you can't click)
//$title  // 要显示的标题(显示在无法单击的特殊选项卡中)
//$notab
//$notab
//$picto  // Name of image to show into title. Possible values are:
//$picto  // 要显示到标题中的图片的名称。可能的值为:
//            product
//            product
//            service
//            service
Line 278: Line 279:


===创建原始PHP屏幕页面===
===创建原始PHP屏幕页面===
随后,您可以使用 '''modulebuilder''' 目录中提供的示例模板('''myobject_page.php''')创建基于表数据的PHP页面(有关命令行脚本的开发,请参阅 [[Script development]] )。同样,如果您使用的是 ModuleBuilder,则在初始化对象时会自动创建页面实例(清单、创建页面、Notes选项卡等)。
随后,您可以使用 '''modulebuilder''' 目录中提供的示例模板('''myobject_page.php''')创建基于表数据的PHP页面(有关命令行脚本的开发,请参阅 [[脚本开发]] )。同样,如果您使用的是 ModuleBuilder,则在初始化对象时会自动创建页面实例(清单、创建页面、Notes选项卡等)。


要创建新的用户屏幕页面,请创建特定于模块的 '''htdocs''' 子目录(如果尚未创建)(如 '''htdocs/mymodule''' ),以便在其中放置要创建的页面。
要创建新的用户屏幕页面,请创建特定于模块的 '''htdocs''' 子目录(如果尚未创建)(如 '''htdocs/mymodule''' ),以便在其中放置要创建的页面。
Line 285: Line 286:


<syntaxhighlight lang="PHP">
<syntaxhighlight lang="PHP">
// Load Dolibarr environment
// 加载Dolibarr环境
$res=0;
$res=0;
// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
// 尝试include在CONTEXT_DOCUMENT_ROOT(不总是定义的)中定义的已知web根目录中的main.inc.php
if (! $res && ! empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) $res=@include($_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php");
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
// 尝试include由SCRIPT_FILENAME计算的web根检测到web根的main.inc.php
$tmp=empty($_SERVER['SCRIPT_FILENAME'])?'':$_SERVER['SCRIPT_FILENAME'];$tmp2=realpath(__FILE__); $i=strlen($tmp)-1; $j=strlen($tmp2)-1;
$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--; }
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(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");
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
// 尝试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 && file_exists("../../main.inc.php")) $res=@include("../../main.inc.php");
if (! $res && file_exists("../../main.inc.php")) $res=@include("../../main.inc.php");
Line 634: Line 635:


请参阅页面 [[Hooks_system|Hooks系统]].
请参阅页面 [[Hooks_system|Hooks系统]].
==添加编号模块(可选)==
==添加编号模块(可选)==
'''何时''':当您想添加默认模块未涵盖的编号规则时。
'''何时''':当您想添加默认模块未涵盖的编号规则时。
Line 666: Line 665:
</syntaxhighlight>
</syntaxhighlight>


=一些编码规则和预定义函数=
=面向开发人员的一些编码规则和函数=
The coding rules to be followed are defined in the [[Developer documentation]], under section "General Information - Language and standards development".
要遵循的编码规则请参阅 [[语言和开发规则|开发语言和编码规范(PHP, SQL, HTML)]] 。


A lot of predefined features for developers are also available and described into page [[Developer documentation]] under section "Technical components of Dolibarr".
要调用 Dolibarr 供开发人员使用的预定义函数,请参阅  [[开发文档]] 的“内部函数”一节。


=创建一个安装包来分发和安装您的模块=
=创建一个安装包来分发和安装您的模块=
This process must be used to generate a package to submit it on the http://www.dolistore.com market place.
必须使用此步骤来制作安装包,以便将其提交到市场 http://www.dolistore.com。
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).
*进入 '''/build''' 目录并将文件 '''makepack-dolibarrmodules.conf''' 复制到 '''makepack-mymodule.conf'''。请注意,稳定版本包中可能不提供此目录。如果是这种情况,可以在 Dolibarr 网站的“开发版本”部分供下载的快照中检索(在这种情况下,请获取整个 build 目录,这是一个独立于版本的目录)。


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...)
在此文件中输入为模块创建的新文件的名称清单(模块描述符、新表的SQL文件、PHP页面、图像等)。


*Run the script via Perl (need the Perl version 5.0 or later):
*通过 Perl 运行脚本(需要Perl 5.0或更高版本):


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
perl makepack-dolibarrmodule.pl
perl makepack-dolibarrmodule.pl
</syntaxhighlight>
</syntaxhighlight>
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:
该脚本将询问模块的名称、主要版本和次要版本。然后将生成一个 '''mymodule.zip '''文件,其中包含准备部署的模块。
 
*接收您的模块的人员必须将该文件放在其 Dolibarr 的安装根目录中,并执行以下命令:


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
Line 692: Line 693:
</syntaxhighlight>
</syntaxhighlight>


*If you want your module to be public, you can submit it (the zip file) on Dolibarr market place web site: {{LinkToPluginDownload}} (you must create an account first and be logged to use the link "Submit a module/product").
*如果您希望您的模块惠及所有人,您可以在插件市场 {{LinkToPluginDownload}} 上提交它(zip文件)(您必须先创建一个帐户并登录,以使用“提交模块/产品”链接)。
**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).
**如果质量足够好、许可证允许、并且模块的功能被证明是普遍感兴趣的,则可以将代码添加到 Dolibarr 的源代码中(除非您不希望这样做)。


=Dolistor上的外部模块的启用/激活条件=
=Dolistore上外部模块的归档和验证=


See [[Module_Dolistore_Validation_Rules|Validation Rules]]
请参阅 [[Module_Dolistore_Validation_Rules|验证规则]]
715

edits