模块开发: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
Line 2: Line 2:
{{TemplateDocDevEn}}
{{TemplateDocDevEn}}
{{Template用户手册}}
{{Template用户手册}}
{{TemplateMainPageZh}}
{{Template开发文档}}


为开发Dolibarr模块,有以下几个步骤,本向导逐步引导你开发模块,扩展Dolibarr功能。包括以下内容 :
为开发Dolibarr模块,有以下几个步骤,本向导逐步引导你开发模块,扩展Dolibarr功能。包括以下内容 :
Line 44: Line 44:
* 创建目录 '''/htdocs/''mymodule''/core/modules'''. 从目录dev/skeletons拷贝文件modMyModule.class.php到新建目录。
* 创建目录 '''/htdocs/''mymodule''/core/modules'''. 从目录dev/skeletons拷贝文件modMyModule.class.php到新建目录。


将 modMyModule.class.php 改名,名称对应于您的模块。 名称以 'mod'开头,以.class.php结尾。 (例如:要创建模块 'NewName', 对应的模块名为'modNewName.class.php').
将 modMyModule.class.php 改名,名称对应于您的模块。 名称以 'mod'开头,以.class.php结尾。 (例如:要创建模块 'NewName', 对应的模块名为'modNewName.class.php').
接下来修改此文件的内容如下:
接下来修改此文件的内容如下:
* 替换所有 "modMyModule",对应于模块名称。 此值须以'mod'开头且仅含字符 (例如,模块为 'NewName', 替换所有 "modMyModule" 为 "modNewName")。
* 替换所有 "modMyModule",对应于模块名称。 此值须以'mod'开头且仅含字符 (例如,模块为 'NewName', 替换所有 "modMyModule" 为 "modNewName")。
Line 66: Line 66:
'''何时''': 模块有自己的数据
'''何时''': 模块有自己的数据


=== 创建 .sql 文件 ===
=== 创建.sql文件 ===
If your module is designed to manage data of its own, which are not available in the standard version of Dolibarr, it is necessary to define SQL tables to store the data.
如果你的模块有自己的数据要管理,而Dolibarr的标准版中没有这些数据,就需要自定义数据库表来存储数据。


Scripts for creating tables and load data for your own module must be placed in a directory: Create a subdirectory called "sql" into directory of your module (eg htdocs/mymodule/sql) to put the sql scripts that you will create.
创建表和加载数据的脚本文件必须放在你的模块目录中创建子目录“sql”中(如htdocs/mymodule/sql)


Then check into your descriptor file, into function '''init''' that the line
检查模块主文件,"init"函数中是否包括行:


<source lang="php">$this->_load_tables('/mymodule/sql/');</source>
<source lang="php">$this->_load_tables('/mymodule/sql/');</source>


is not commented.


''Rules to follow:''
''规则:''
* Add the files about creating tables commands on the principle of a file '''llx_matable.sql''' per table, with a possibly file '''llx_matable.key.sql''' (see existing files in '''install/mysql/tables''' for examples).
* 新建表的命令在文件 '''llx_matable.sql''' , 或者还有 '''llx_matable.key.sql''' (参见 '''install/mysql/tables''' 实例).


* To manage data, you must create a file called '''data.sql''' inside directory '''/mymodule/sql/''' that contains SQL command to add/edit/delete data.
* 管理数据:在目录 '''/mymodule/sql/'''中创建文件 '''data.sql''' 文件中包括增删模改数据的命令。
* Don't use the double quote for strings (eg 'chaine' not "chaine") because the double quote have a specific meaning in PostGreSQL
* 不要使用双引号 (如使用 'chaine' 而不使用 "chaine") 因为双引号有特殊意义(PostGreSQL)。
Example of content of a file data.sql
data.sql实例
<source lang="sql">
<source lang="sql">
  delete from llx_const where name='MYMODULE_IT_WORKS' and entity='__ENTITY__';
  delete from llx_const where name='MYMODULE_IT_WORKS' and entity='__ENTITY__';
Line 88: Line 87:
</source>
</source>


Files must be operational for the database mysql. Rem: The files of other databases are not maintained. They will be read and converted on the fly by the driver of the other database.
对于MySQL数据库,文件必须是可操作的。REM:其他数据库的文件不被维护。它们将由另一个数据库的驱动程序进行读取和转换。


=== 测试 .sql 文件 ===
=== 测试 .sql 文件 ===


Once the files ready, you can return to Dolibarr to disable the module, drop those tables in database and reactivate the module. The tables should be recreated by the activation of the module. If this is not the case, check your scripts by passing them by hand, or check the Dolibarr logs.
一旦文件准备就绪,您可以返回Dolibarr以禁用该模块,在数据库中将模块使用的表删除,并重新激活模块。应该能通过激活模块来重新创建表。否则,请通过手动传递脚本,或者检查Dolibarr日志。


=== Generate the PHP DAO class ===
=== 生成 PHP DAO 类文件 ===
Once you have created your tables into the database, move to the dev/skeletons directory and run the script
Once you have created your tables into the database, move to the dev/skeletons directory and run the script


513

edits

Navigation menu