脚本开发: Difference between revisions

Jump to navigation Jump to search
no edit summary
(Created page with "Category:Core {{TemplateDocDev}} = Location = The Dolibarr command line scripts must be located in the '''scripts''' directory in Dolibarr root. The scripts are then divided...")
 
No edit summary
Line 1: Line 1:
[[Category:Core]]
[[Category:Core]]
{{TemplateDocDev}}
{{Template开发文档}}
{{Template用户手册}}
{{TemplateMainPageZh}}


= Location =
= 位置 =
The Dolibarr command line scripts must be located in the '''scripts''' directory in Dolibarr root. The scripts are then divided into sub-directories according to their vocation. A number of scripts is provided as standard.
Dolibarr命令行脚本必须位于Dolibarr根目录下的 '''scripts'''目录中。脚本然后根据其使命划分为子目录。提供多个脚本作为标准。


= Develop a new script =
= 开发新脚本 =
The scripts are often made for a specific need, it is likely that you do not find the one you want. In this case, we'll explain how to develop your own script.
脚本通常是针对特定需求而编写的,很可能你找不到你想要的脚本。在这种情况下,我们将解释如何开发自己的脚本。


== Step 1 - Create the skeleton of the script ==
== Step 1 - 创建脚本的框架 ==
The first step is to take the skeleton script available in '''dev/skeletons/skeleton_scripts.php''' and copy and renaming it in directory '''scripts/mydir/myscript.php'''
第一步是在'''dev/skeletons/skeleton_scripts.php''' 中获取骨架脚本并在目录'''scripts/mydir/myscript.php'''中复制和重命名它。


Once renaming is done, give it permissions to execute.
一旦重命名完成,就给它执行权限。
On linux, this is the command:
 
在Linux上,这是命令:
<source lang="bash">
<source lang="bash">
cd scripts/mydir;
cd scripts/mydir;
chmod a+rx myscript.php
chmod a+rx myscript.php
</source>
</source>
Then, run it to see if you can run the script in a command line mode. For this, on Linux, type:
然后,运行它以查看是否可以在命令行模式下运行脚本。为此,在Linux上,键入:
<source lang="bash">
<source lang="bash">
php-cli ./myscript.php
php-cli ./myscript.php
</source>
</source>
or
或者
<source lang="php">
<source lang="php">
php ./myscript.php
php ./myscript.php
</source>
</source>
You must get the following output:
必须获得以下输出:
<source lang="bash">
<source lang="bash">
Usage: myscript.php param1 param2 ...
Usage: myscript.php param1 param2 ...
</source>
</source>


== Step 2 - Editing script code ==
== Step 2 - 编辑脚本代码 ==
Modify the contents of the script to perform operations that interest you.
修改脚本的内容以执行对您感兴趣的操作。
All the code that lies between the tags
 
标签之间的所有代码
<source lang="php">// ---------- START OF YOUR CODE HERE</source>
<source lang="php">// ---------- START OF YOUR CODE HERE</source>
and
和
<source lang="php">// ---------- END OY YOUR CODE</source>
<source lang="php">// ---------- END OY YOUR CODE</source>
is provided as an example.
是提供的一个例子。
You can delete it and put the code that you want.
 
Note that in this section, you can use the variable $db that is the resource to access Dolibarr database and is already initialized. The $conf object that contains Dolibarr configuration is also available.
你可以删除它并把你想要的代码放进去。
 
请注意,在本节中,可以使用变量$db来访问Dolibarr数据库并已初始化。包含Dolibarr配置的 $conf对象也是可用的。


= Examples =
= 例子 =
Some code examples (to create orders, products...) are available into directory '''/dev/examples/'''.
一些代码示例(创建订单、产品…)可用于目录'''/dev/examples/'''中。
513

edits

Navigation menu