|
|
| Line 69: |
Line 69: |
|
| |
|
| == 模块文件路径树(必需)== | | == 模块文件路径树(必需)== |
| | |
| 模块组织文件的方法(zip文件须与此匹配)。 | | 模块组织文件的方法(zip文件须与此匹配)。 |
|
| |
|
| Line 113: |
Line 114: |
| 已经生成了一个文件'''out.tablename_script.php''',并包含一个示例代码,使用了4个CRUD方法中的每一个。 | | 已经生成了一个文件'''out.tablename_script.php''',并包含一个示例代码,使用了4个CRUD方法中的每一个。 |
|
| |
|
| ''自从Dolibarr 6.0开,不再提供文件dev/skeletons/build_class_from_table.php。要从一个表生成一个类,您应该使用ModuleBuilder模块。 | | ''自从Dolibarr 6.0开,不再提供文件'''dev/skeletons/build_class_from_table.php'''。要从一个表生成一个类,您应该使用'''ModuleBuilder'''模块。 |
|
| |
|
| === 使用ModuleBuilder生成PHP DAO类文件 === | | === 使用ModuleBuilder生成PHP DAO类文件 === |
| Line 145: |
Line 146: |
|
| |
|
| 要用数据库中的数据来填充选项卡的内容,请参阅下一章。 | | 要用数据库中的数据来填充选项卡的内容,请参阅下一章。 |
|
| |
| 若tabs数组有任何问题,选项卡不会显示,也不报错。
| |
|
| |
| 模块需重新激活,否则不会显示。
| |
|
| |
|
| === 在你的页上显示选项卡导航 === | | === 在你的页上显示选项卡导航 === |
| Line 247: |
Line 244: |
| if (! $res) die("Include of main fails"); | | if (! $res) die("Include of main fails"); |
| </source> | | </source> |
| 注: 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.
| | 在3.2之后,为所有版本的Dolibarr开发的模块应该能够在不同的文件夹中移动,而不是“htdocs”,比如“htdocs/custom”,而不必修改模块的源代码,这就是为什么我们要做几个包含,所以这个规则必须被所有模块应用。 |
|
| |
|
| 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:
| | 在main.inc.php文件中,加载了技术环境变量和权限。以下变量是位于该文件中的对象: |
|
| |
|
| * $user Objet that contains the characteristics of the user + his permissions. | | * $user 包含用户+ 权限。Objet that contains the characteristics of the user + his permissions. |
| * $conf Objet that contains Dolibarr configuration. | | * $conf 包含 Dolibarr 设置 |
| * $db Objet that contains an opened connection handler to the database. | | * $db 它包含一个打开的数据库连接处理程序。 |
| * $langs Objet that contains the user's language. | | * $langs 包含用户语言 |
|
| |
|
| 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): | | * 包含模块专属的类或库,使用Dolibarr函数dol_include_once()(而不是直接使用 include_once): |
| ''Example :'' | | ''例如 :'' |
| <source lang="php"> | | <source lang="php"> |
| dol_include_once('/mymodule/class/myclass.class.php', 'MyClass'); | | dol_include_once('/mymodule/class/myclass.class.php', 'MyClass'); |
| </source> | | </source> |
|
| |
|
| * To include classes provided with Dolibarr, use the following syntax: | | * 若要包含Dolibarr提供的类,请使用以下语法: |
| ''Example :'' | | ''例如 :'' |
| <source lang="php"> | | <source lang="php"> |
| require_once DOL_DOCUMENT_ROOT.'/core/class/doli.class.php'; | | require_once DOL_DOCUMENT_ROOT.'/core/class/doli.class.php'; |
| Line 272: |
Line 269: |
|
| |
|
| === 为现存表单增加新字段 === | | === 为现存表单增加新字段 === |
| You may want to provide a module that add more fields into forms (input and view) of some elements.
| | 您可能需要提供一个模块,该模块将更多字段添加到一些元素的表单(输入和查看)中。 |
| | |
| | 一个较累的解决方案(但不是很糟糕)是替换所有用于创建元素的页面(这意味着禁用“新元素”菜单条目并添加您的,禁用“显示”元素,用一个选项卡替换该元素,该选项卡是您自己的完整页面(从原始复制/粘贴),以完成与原始页面相同的操作,修改以添加字段并将添加的数据存储到自己的表中)。 |
| | |
| | 转到菜单 [[#Define your entries in menu (optional)]]和[[#The tab management (optional)]],如果这个解决方案适合你(这个解决方案是更强大的,因为你可以改变你想要的一切进入页面)。 |
|
| |
|
| 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).
| | 我们将在这里描述另一种解决方案,它只在现有字段结束时“添加字段”,使用元素“category”作为示例,但您可以将此教程转换为发票、提案… |
|
| |
|
| 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 ...
| | * 首先,添加一个由您的模块所拥有的表,以存储新字段的值。此表有一个名为“rowid”的列(将包含与元素表的字段rowid相同的值+每一个要添加的新字段的列。然后为这个新表创建一个CRUD(创建/读取/更新/删除)方法类。对于这两个任务,请回到前一章[[#创建数据表和表的PHP类文件 (可选)]]。 |
| * 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]]. | | *下一步是在模块中添加一个钩子,以将新字段添加到窗体中。有关使用钩子的通用文档,请参见[[Hooks_system#Implement_the_Hook]]章节。 |
| * 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:
| |
| {{ToComplete}} | | {{ToComplete}} |
|
| |
|
| === 替换模板的部分内容 (version 3.3+) === | | === 替换模板的部分内容 (version 3.3+) === |
| Some parts of Dolibarr screen are isolated into native PHP template files.
| | Dolibarr屏幕的一些部分被隔离到本地PHP模板文件中。 |
| You can develop a module to overwrite such templates with yours.
| | 您可以开发一个模块来覆盖这样的模板。 |
| {{ToComplete}} | | {{ToComplete}} |
|
| |
|
| === 增/换部分字段(需钩子支持) === | | === 增/换部分字段(需钩子支持) === |
| See chapter [[Hooks_system#Implement_the_Hook]] to know how to use Dolibarr existing hooks to add/replace code at Dolibarr hooks place.
| | 要知道如何使用Dolibarr现有的钩子来添加/替换Dolibarr 钩子代码,参考 [[Hooks_system#Implement_the_Hook]] 。 |
|
| |
|
| === 数据通道 === | | === 数据通道 === |
| If you need to edit some data in database inside you own table, use the PHP class generated before.
| | 如果需要在自己的表中编辑数据库中的一些数据,请使用的PHP类。 |
|
| |
|
| 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:
| | 如果您要访问没有专用PHP类的表(例如,如果您想获得具有特定连接或筛选器的记录列表)。在这种情况下,这是要遵循的代码示例: |
|
| |
|
| To make an insert, update or delete:
| | 进行插入、更新或删除: |
|
| |
|
| <source lang="php"> | | <source lang="php"> |
| Line 304: |
Line 304: |
| </source> | | </source> |
|
| |
|
| To read:
| | 读: |
|
| |
|
| <source lang="php"> | | <source lang="php"> |
| Line 330: |
Line 330: |
|
| |
|
| === 页面风格 === | | === 页面风格 === |
| To have the look of your own pages to match the Dolibarr theme, it is necessary to use the Dolibarr CSS styles.
| | 为了让你自己的页面看起来与Dolibarr主题相匹配,必须使用Dolibarr CSS样式。 |
|
| |
|
| You can use for example:
| | 例如,您可以使用: |
|
| |
|
| * class="'''liste_titre'''" on tags ''tr'' and ''td'' for the head row of a table. | | * class="'''liste_titre'''" on tags ''tr'' and ''td'' for the head row of a table. |
| Line 340: |
Line 340: |
|
| |
|
| === 使用Dolibarr日期选择器 === | | === 使用Dolibarr日期选择器 === |
| If you want to use the Dolibarr date selector (with its calendar popup) into your pages, use the following line:
| | 如果您的页面使用Dolibarr日期选择器(日历弹出),请使用以下行: |
| <source lang="php"> | | <source lang="php"> |
| $form=new Form($db); | | $form=new Form($db); |
| $form->select_date('','mykey',0,0,0,"myform"); | | $form->select_date('','mykey',0,0,0,"myform"); |
| </source> | | </source> |
| 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.
| | 字符串mykey将标识表单中的日期选择器。如果在同一页中使用多个日期选择器,则必须使用不同的值。 |
| 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.
| | 字符串myform是包含选择器的表单的名称(在HTML页面中的form name="myform")中找到的值。 |
| | |
| | 这意味着日期选择器必须包含在HTML表单中。 |
|
| |
|
| To get value after the POST of your form, the command is:
| | 要获得表单POST的值,命令是: |
| <source lang="php"> | | <source lang="php"> |
| $mydate = dol_mktime(12, 0 , 0, $_POST['mykeymonth'], $_POST['mykeyday'], $_POST['mykeyyear']); | | $mydate = dol_mktime(12, 0 , 0, $_POST['mykeymonth'], $_POST['mykeyday'], $_POST['mykeyyear']); |
| Line 356: |
Line 358: |
|
| |
|
| == 新增设置页 (可选) == | | == 新增设置页 (可选) == |
| '''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|table '''llx_const''']]).
| | 如果模块需要设置几个参数,则必须创建一个页面来编辑选项。 (这些制作存储于 [[Table llx_const|表 '''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.
| | 新建 '''mymodule_setuppage.php''' 这显示了可能的选项的表单,将它们更新到上面提到的表中。 |
| Put this PHP page into the directory '''/admin''' of your module (e.g. mymodule/admin/mymodule_setuppage.php).
| | |
| | 有必要从目录''/admin ''的页面中获取一个示例,它将向您展示读取/保存参数的方法。 |
| | |
| | 把这个PHP页面放到你的模块的''/admin ''(例如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.
| | 然后,在模块主文件中,将变量“config_page_url”修改为PHP页面的设置名称。 |
| If the page is in the directory '''admin/''', then the path is not required, e.g. like this:
| | |
| | 如果页面位于目录'''admin/'''中,则不需要路径,例如: |
| <source lang="php"> | | <source lang="php"> |
| $this->config_page_url = array("mymodule_setuppage.php"); | | $this->config_page_url = array("mymodule_setuppage.php"); |
| </source> | | </source> |
| If the page is in the directory '''mymodule/admin/''', then like this:
| | |
| | 如果页面在目录 '''mymodule/admin/'''中,则像这样: |
| <source lang="php"> | | <source lang="php"> |
| $this->config_page_url = array("mymodule_setuppage.php@mymodule"); | | $this->config_page_url = array("mymodule_setuppage.php@mymodule"); |
| Line 376: |
Line 383: |
|
| |
|
| === 测试页面 === | | === 测试页面 === |
| 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. | | '''何时''': 如果您创建了PHP页面,则必须从Dolibarr菜单中的菜单条目中访问这些页面。 |
|
| |
|
| === 增加菜单条目 === | | === 增加菜单条目 === |