513
edits
No edit summary |
|||
| Line 54: | Line 54: | ||
=== 创建模块主文件 === | === 创建模块主文件 === | ||
创建模块主文件. | 创建模块主文件. | ||
* 创建目录 '''/htdocs/''mymodule''/core/modules'''. | * 创建目录 '''/htdocs/''mymodule''/core/modules'''. 从目录/modulebuilder/template/core/modules拷贝文件modMyModule.class.php到新建目录。 | ||
将 modMyModule.class.php | 将 modMyModule.class.php 改名,名称对应于您的模块。名称以 'mod'开头,以.class.php结尾。 (例如:要创建模块 'NewName', 对应的模块名为'modNewName.class.php'). | ||
接下来修改此文件的内容如下: | 接下来修改此文件的内容如下: | ||
* 替换所有 "modMyModule",对应于模块名称。 此值须以'mod'开头且仅含字符 (例如,模块为 'NewName', 替换所有 "modMyModule" 为 "modNewName")。 | * 替换所有 "modMyModule",对应于模块名称。 此值须以'mod'开头且仅含字符 (例如,模块为 'NewName', 替换所有 "modMyModule" 为 "modNewName")。 | ||
| Line 86: | Line 86: | ||
<source lang="php">$this->_load_tables('/mymodule/sql/');</source> | <source lang="php">$this->_load_tables('/mymodule/sql/');</source> | ||
''规则:'' | ''规则:'' | ||
* 新建表的命令在文件 '''llx_matable.sql''' , 或者还有 '''llx_matable.key.sql''' (参见 '''install/mysql/tables''' 实例). | * 新建表的命令在文件 '''llx_matable.sql'''中, 或者还有 '''llx_matable.key.sql''' (参见 '''install/mysql/tables''' 实例). | ||
* 管理数据:在目录 '''/mymodule/sql/'''中创建文件 '''data.sql''' 文件中包括增删模改数据的命令。 | * 管理数据:在目录 '''/mymodule/sql/'''中创建文件 '''data.sql''' 文件中包括增删模改数据的命令。 | ||
* 不要使用双引号 (如使用 'chaine' 而不使用 "chaine") 因为双引号有特殊意义(PostGreSQL)。 | * 不要使用双引号 (如使用 'chaine' 而不使用 "chaine") 因为双引号有特殊意义(PostGreSQL)。 | ||
| Line 106: | Line 104: | ||
=== 生成 PHP DAO 类文件 === | === 生成 PHP DAO 类文件 === | ||
一旦将表创建到数据库中,就转到DEV/Skeleto目录 | |||
<source lang="bash">php build_class_from_table.php tablename modulename</source> | <source lang="bash">php build_class_from_table.php tablename modulename</source> | ||
注意:如果命令不工作,尝试使用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类文件,简单至在下图中选对'对象'选项卡,输入'对象名',然后点击创建,即可生成相关一切文档。 | |||
[[File:新对象.png|800px]] | |||
参见[[ModuleBuilder用户手册]] | |||
== 选项卡管理(可选) == | == 选项卡管理(可选) == | ||
| Line 124: | Line 125: | ||
'''何时''': 增加对象选项卡 (对象是指‘发票’、‘订单’、‘提议’、‘会员’等等) | '''何时''': 增加对象选项卡 (对象是指‘发票’、‘订单’、‘提议’、‘会员’等等) | ||
为此,进入先前创建的模块主文件,并编辑$this->tabs数组: | |||
<source lang="php"> | <source lang="php"> | ||
| Line 133: | Line 134: | ||
</source> | </source> | ||
该数据包含一个字符串列表,每个字符串表示一个新选项卡。 | |||
字符串由":"分隔的5个部分组成。 | |||
* Part 1: | * Part 1: 选项卡出现在的对象类型(objecttype),只能是以下值: | ||
{{TemplateModuleTabs}} | {{TemplateModuleTabs}} | ||
* Part 2: | * Part 2: 标识选项卡是添加(以+开始)或移除(以-start)的代码 | ||
* Part 3: | * Part 3: 选项卡的标题。这可以是lang文件中的译文代码或者是一个直接的字符串。 | ||
* Part 4: | * Part 4: 文件“*.lang”的名称,包含译文代码和要显示的语言之间的对应关系。如果这个名字跟随 @mymodule,Dolibarr将搜索模块内的翻译文件“*.lang”,即"htdocs/mymodule/langs/code_CODE/mylangfile.lang"。否则Dolibarr将查找文件"htdocs/langs/code_CODE/mylangfile.lang" | ||
* Part 5: | * Part 5: 测试选项卡是否必须可见的条件。为1则一直可见。 | ||
* Part 6: | * Part 6: 单击选项卡时要显示的页面的URL。字符串__ID__将由相关元素的ID自动替换。 | ||
要用数据库中的数据来填充选项卡的内容,请参阅下一章。 | |||
=== 在你的页上显示选项卡导航 === | === 在你的页上显示选项卡导航 === | ||
''' | '''何时''': 在页面上显示对象的所有标准选项卡(产品、第三方等)。 | ||
你必须遵循这些步骤: | |||
'''1. | '''1. 包含文件中需要的文件''' | ||
对于每个对象类型,有两个文件要包含。 | |||
<source lang="php">require_once($url_fichier) ;</source> | <source lang="php">require_once($url_fichier) ;</source> | ||
包含示例 (DOL_DOCUMENT_ROOT 代表 dolibarr/htdocs/) : | |||
* | * 对象第三方(thirdparty) : | ||
** DOL_DOCUMENT_ROOT/societe/class/societe.class.php | ** DOL_DOCUMENT_ROOT/societe/class/societe.class.php | ||
** DOL_DOCUMENT_ROOT/core/lib/company.lib.php | ** DOL_DOCUMENT_ROOT/core/lib/company.lib.php | ||
* | * 对象产品(product) : | ||
** DOL_DOCUMENT_ROOT/product/class/product.class.php | ** DOL_DOCUMENT_ROOT/product/class/product.class.php | ||
** DOL_DOCUMENT_ROOT/core/lib/product.lib.php | ** DOL_DOCUMENT_ROOT/core/lib/product.lib.php | ||
* | * 对象发票 (invoice) : | ||
** DOL_DOCUMENT_ROOT/compta/facture/class/facture.class.php | ** DOL_DOCUMENT_ROOT/compta/facture/class/facture.class.php | ||
** DOL_DOCUMENT_ROOT/core/lib/invoice.lib.php | ** DOL_DOCUMENT_ROOT/core/lib/invoice.lib.php | ||
... | ... | ||
'''2. | '''2. 创建并加载对象以显示在您的选项卡中''' | ||
通过从url(ie : /mytab.php?id=1)获取的id值,使用对象的获取方法,从数据库中创建正确的类和加载对象的实例。 | |||
'' | ''例如:'' | ||
<source lang="php"> | <source lang="php"> | ||
$id=GETPOST('id','int'); | $id=GETPOST('id','int'); | ||
| Line 179: | Line 180: | ||
</source> | </source> | ||
'''3. | '''3. 为你的对象类型获取所有可显示的选项卡列表''' | ||
使用函数XXX_prepare_head($obj),其中XXX是对象的名称。这将返回一个数组,包含所有选项卡条目的定义。要放入该方法的参数是要显示选项卡的对象实例。 | |||
返回的数组为: | |||
<source lang="php"> | <source lang="php"> | ||
$head // Array of tabs | $head // Array of tabs | ||
| Line 192: | Line 193: | ||
</source> | </source> | ||
'' | ''例如 :'' | ||
<source lang="php"> | <source lang="php"> | ||
$head = product_prepare_head($product, $user) ; // | $head = product_prepare_head($product, $user) ; // 参数 $user 是要显示选项卡的对象,这就是"产品"对象为"user"对象准备的所有可用的选项卡的数组。 | ||
</source> | </source> | ||
'''4. | '''4. 在你的页面上显示选项卡''' | ||
使用函数dol_fiche_head()显示由函数XX_prepare_head()返回的$head数组定义的定义的所有选项卡。 | |||
<source lang="php"> | <source lang="php"> | ||
| Line 215: | Line 216: | ||
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. | 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 屏显 === | ||
然后,您必须创建PHP页面,使用目录'''modulebuilder/myobject_page.php'''中提供的框架模板来显示/编辑表中的数据。 (从命令行开发脚本, 见 [[Script development]]). | |||
要创建一个新的用户屏幕,创建一个模块名的子目录(若无) (例如 '''htdocs/mymodule''') 来存储创建的屏幕。 | |||
复制 '''myobject_page.php''' 做为屏幕页。 | |||
编辑该文件,以包括正确的 '''main.inc.php'''文件。 | |||
<source lang="php"> | <source lang="php"> | ||
// Load Dolibarr environment | // Load Dolibarr environment | ||
| Line 241: | Line 243: | ||
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. | 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. | ||
| Line 265: | Line 267: | ||
</source> | </source> | ||
=== | === 为现存表单增加新字段 === | ||
You may want to provide a module that add more fields into forms (input and view) of some elements. | You may want to provide a module that add more fields into forms (input and view) of some elements. | ||
edits