Line 2:
Line 2:
<!-- Do NOT edit this section
<!-- Do NOT edit this section
Links below are automatically managed by PolyglotBot
Links below are automatically managed by PolyglotBot
−
You can edit links on the English source page : Sprachen_und_Programmierregeln -->
+
You can edit links on the English source page : Language_and_development_rules -->
−
[[en:Sprachen_und_Programmierregeln]]
+
[[en:Language_and_development_rules]]
[[fr:Langages_et_normes]]
[[fr:Langages_et_normes]]
[[es:Lenguaje_y_Normas_de_Desarrollo]]
[[es:Lenguaje_y_Normas_de_Desarrollo]]
Line 9:
Line 9:
<!-- END interlang links -->
<!-- END interlang links -->
−
{{TemplateDocDevEn}}
+
{{TemplateDocDevDe}}
−
These are some rules on language, syntax and norm we use in the Dolibarr project:
+
Nachfolgend einige Regeln zu Sprache, Syntax und Norm, die wir im Dolibarr-Projekt verwenden:
−
=Versions=
+
=Übersetzung nicht vollständig=
+
{{ToCompleteDE}}
−
*Dolibarr must work on:
+
=Versionen=
−
#All OS (Windows, Linux, MACOS...)
+
*Dolibarr muss funktionieren mit:
−
#PHP {{PHPMinVersion}} (Must work with no need of complementary PHP module, except module to PHP module to access database).
+
+
#Allen Betriebssystemen (Windows, Linux, MACOS...)
+
#PHP {{PHPMinVersion}} (Muss ohne komplementäres PHP-Modul funktionieren, außer Modul zu PHP-Modul, um auf die Datenbank zuzugreifen).
#MySQL {{MySqlMinVersion}}
#MySQL {{MySqlMinVersion}}
−
=Copyright Norms=
+
=Urheberrechtsnormen=
−
*All PHP files must start with a header that looks like
+
*Alle PHP-Dateien müssen mit einem Header beginnen, der folgendermaßen aussieht
−
<source lang="php">
+
<syntaxhighlight lang="php">
<?php
<?php
/* Copyright (C) YYYY John Doe <email@email.com>
/* Copyright (C) YYYY John Doe <email@email.com>
Line 32:
Line 35:
*/
*/
...
...
−
</source>
+
</syntaxhighlight>
−
When you edit an existing file of project, you must add a Copyright line under others.
+
Wenn Sie eine vorhandene Projektdatei bearbeiten, müssen Sie eine neue Copyright-Zeile im Header hinzufügen.
−
=PHP Norms=
+
=PHP-Normen=
==PHP==
==PHP==
−
*Dolibarr is written with PHP and supports all versions of PHP higher than {{PHPMinVersion}}. All files must end with extension .php
+
*Dolibarr ist in PHP geschrieben und unterstützt alle Versionen von PHP, welche höher sind, als {{PHPMinVersion}}. Alle Dateien müssen mit der Erweiterung .php enden.
−
*Usage of PHP superglobals variables must use the dedicated operators $_COOKIES, $_SERVER, $_ENV but use the Dolibarr function GETPOST() to get the contents of $_GET or $_POST..
+
*Die Verwendung von PHP superglobalen Variablen muss über die festgelegten Operatoren $_COOKIE, $_SERVER, $_ENV erfolgen.
+
*Allerdings muss die Dolibarr-Funktion GETPOST () verwendet werden, um den Inhalt von $_GET oder $_POST abzurufen.
−
*Other operators ($HTTP_SERVER_GET, ...) are now deprecated in PHP, so they must not be used. Code must work if option '''register_long_arrays''' is set to off. Moreover, the code must work when PHP option '''register_globals''' is off (recommended by PHP). It must also work if the option '''register_globals''' is on (by default on a lot of installations).
+
*Andere Operatoren wie ($HTTP_SERVER_GET, ...) sind veraltet und dürfen daher nicht verwendet werden. Der Code muss funktionieren, wenn die Option '''register_long_arrays''' deaktiviert ist. Desweiteren muss der Code funktionieren, wenn die PHP-Option '''register_globals''' deaktiviert ist (wird von PHP empfohlen). Allerdings muss er auch funktionieren wenn die Option '''register_globals''' aktiviert ist (standardmäßig bei vielen Installationen).
−
*Do not use '''<s>PHP_SELF</s>'''. Use instead '''$_SERVER["PHP_SELF"]'''. Also, Dolibarr framework sanitizes content of $_SERVER["PHP_SELF"] variable (into main.inc.php file, before any business code).
+
*Verwenden Sie nicht '''<s>PHP_SELF</s>'''. Stattdessen verwenden Sie '''$_SERVER["PHP_SELF"]'''. Beachten Sie weiterhin, dass das Dolibarr-Framework den Inhalt der Variablen $_SERVER["PHP_SELF"] bereinigt. (Siehe Datei '''main.inc.php''').
−
*When several variables must be initialized with the same value, you must use individual declarations (separated by ;)
+
*Wenn mehrere Variablen mit demselben Wert initialisiert werden sollen, müssen Sie einzelne Deklarationen verwenden (getrennt durch ''';''' ).
−
<source lang="php">
+
<syntaxhighlight lang="php">
$var1=1;
$var1=1;
$var2=1;
$var2=1;
$var3=1;
$var3=1;
−
</source>
+
</syntaxhighlight>
−
instead of
+
Anstelle von
−
<source lang="php">
+
<syntaxhighlight lang="php">
$var1=$var2=$var3=1;
$var1=$var2=$var3=1;
−
</source>
+
</syntaxhighlight>
−
which is slower.
+
, weil es langsamer ist.
<br />
<br />
Line 63:
Line 67:
====Strings====
====Strings====
−
*Strings must be delimited by a single or double quote and a variable within the string must be outside of the quote.
+
*Zeichenfolgen müssen durch einfache oder doppelte Anführungszeichen begrenzt sein. Eine Variable innerhalb der Zeichenfolge muss außerhalb der Anführungszeichen liegen.
−
<source lang="php">
+
<syntaxhighlight lang="php">
print 'My text show my '.$variable.' !';
print 'My text show my '.$variable.' !';
−
</source>
+
</syntaxhighlight>
<br />
<br />
−
====Comments====
+
====Kommentare====
−
*Comments must use the C syntax, ie a double slash for a comment on one line and a slash-star to open a bloc for several lines
+
*Kommentare müssen die C-Syntax verwenden, das heißt einen doppelten Schrägstrich für einen Kommentar in einer Zeile oder einen Schrägstrich mit Stern, um einen Block für mehrere Zeilen zu öffnen
−
<source lang="php">
+
<syntaxhighlight lang="php">
−
/* Bloc of comment
+
/* Kommentarblock
*
*
−
* End of bloc
+
* Blockende
*/
*/
Line 85:
Line 89:
for ($i = 1 , $i < 2 ; $i++) {
for ($i = 1 , $i < 2 ; $i++) {
−
// comment on one line
+
// Kommentar in einer Linie
print $i;
print $i;
}
}
Line 91:
Line 95:
function myFunction($param1, $param2)
function myFunction($param1, $param2)
{
{
−
// code
+
// Code
}
}
−
</source>
+
</syntaxhighlight>
−
−
<br />
−
*Functions must return a value equal or higher than 0 if successful and strictly lower than 0 if error.
+
*Funktionen müssen bei Erfolg einen Wert zurückgeben, der größer/gleich 0 ist und bei Fehlern zwingend kleiner als 0 ist
−
*No dead code (code never used) into Dolibarr core code (code used by external modules only must be included within the external modules).
+
*Es darf kein Code im Dolibarr-Kerncode vorhanden sein, welcher nur von Externen Modulen verwendet wird (Toter Code). Code von externen Modulen muss in den externen Modulen enthalten sein.
−
*Use "include_once" for anything with functions or class definitions in it (like *.class.php and *.lib.php files), use "include" for template-style php with files containing common part of HTML and PHP code (like *.inc.php and *.tpl.php files).
+
*Verwenden Sie "include_once" für alles, was Funktionen oder Klassendefinitionen enthält (wie * .class.php- und * .lib.php-Dateien), und "include" für PHP-Dateien im Vorlagenstil, die HTML- und PHP-Code enthalten (wie * .inc.php und * .tpl.php Dateien).
−
*Coding style to use is the '''PSR-12''' (https://www.php-fig.org/psr/psr-12/). Only rules tagged "MUST" are currently required. So note however the exceptions:
+
*Der zu verwendende Codierungsstil ist '''PSR-12''' (https://www.php-fig.org/psr/psr-12/). Nur die Regeln, welche mit "Muss" gekennzeichnet sind, sind absolut zwingend. Beachten Sie die folgenden Ausnahmen:
**Length of line: PSR-12 mention we can't go up to 120 characters on same line, this is a soft limit. It is better to have long lines instead of long page with code content that is just data declaration and does not contain any logic. However, we introduced a hard limit of '''1000''' characters (having line larger than this may return errors on Continuous Integration tests).
**Length of line: PSR-12 mention we can't go up to 120 characters on same line, this is a soft limit. It is better to have long lines instead of long page with code content that is just data declaration and does not contain any logic. However, we introduced a hard limit of '''1000''' characters (having line larger than this may return errors on Continuous Integration tests).
**Tabs are allowed: The other exception is that we don't replace systematically the tabs with spaces. Using tabs is more convenient for most editors/developers. Also using spaces breaks some auto-format features (like Eclipse autoformat feature on some Eclipse version). For the moment, the best setup is "Keep spaces/tabs as it is", however, you can activate the option "Remove spaces at end of lines".
**Tabs are allowed: The other exception is that we don't replace systematically the tabs with spaces. Using tabs is more convenient for most editors/developers. Also using spaces breaks some auto-format features (like Eclipse autoformat feature on some Eclipse version). For the moment, the best setup is "Keep spaces/tabs as it is", however, you can activate the option "Remove spaces at end of lines".
Line 120:
Line 122:
{{TemplatePHPFields}}
{{TemplatePHPFields}}
−
=SQL rules=
+
=SQL Standards=
−
==DDL file format==
+
==Dateiformat DDL==
−
Files containing definition of the database structure (DDL files) must be '''2 per table''':
+
Dateien, die die Definition der Datenbankstruktur enthalten (DDL-Dateien), benötigen 2 pro Tabelle:
−
*The first file defines the table and its fields. The file name contains the table name, e.g. like this: <tt>llx_''mytable''.sql</tt>
+
*Die erste Datei definiert die Tabelle und ihre Felder. Der Dateiname enthält den Tabellennamen, z. B. so: llx_mytable.sql
−
A comment will be added for each field to explain its usage.
+
Alle Tabellen sind mit einem Präfix versehen, um Namenskonflikte zu vermeiden. Das Präfix kann bei der Installation geändert werden. Der Standardwert ist llx_.
−
*The second file defines all foreign keys, performance indexes or other constraints and the file name will be like: <tt>llx_''mytable''.key.sql</tt>
+
Zu jedem Feld wird ein Kommentar hinzugefügt, um seine Verwendung zu erläutern.
+
Die zweite Datei definiert alle Fremdschlüssel, Leistungsindizes oder andere Einschränkungen und der Dateiname lautet: llx_mytable.key.sql
−
These files must be stored in the directory '''install/mysql/tables''' for all standard files or '''mymodule/tables''' for tables provided by an external module.
+
Diese Dateien müssen im Verzeichnis install/mysql/tables für alle Standarddateien oder im Verzeichnis mymodule/tables für Tabellen, die von einem externen Modul bereitgestellt werden, gespeichert werden.
Example: '''file for creating the table llx_mytable will be llx_mytable.sql''':
Example: '''file for creating the table llx_mytable will be llx_mytable.sql''':
−
<source lang="sql">
+
<syntaxhighlight lang="sql">
-- ===========================================================================
-- ===========================================================================
-- Copyright (C) 2013 Author <email@author.com>
-- Copyright (C) 2013 Author <email@author.com>
Line 168:
Line 171:
fk_user_mod integer NOT NULL, -- Last updater, foreign key of llx_user
fk_user_mod integer NOT NULL, -- Last updater, foreign key of llx_user
import_key varchar(14) -- Use by import process
import_key varchar(14) -- Use by import process
−
)type=innodb;
+
)type=innodb;</syntaxhighlight>
−
</source>
Example: '''file for creating keys/indexes for the table llx_mytable will be llx_mytable.key.sql''':
Example: '''file for creating keys/indexes for the table llx_mytable will be llx_mytable.key.sql''':
−
<source lang="sql">
+
<syntaxhighlight lang="sql">
-- ===========================================================================
-- ===========================================================================
-- Copyright (C) 2013 Author <email@author.com>
-- Copyright (C) 2013 Author <email@author.com>
Line 194:
Line 196:
ALTER TABLE llx_mytable ADD CONSTRAINT fk_mytable_fk_field FOREIGN KEY (fk_field) REFERENCES llx_matablepere (rowid);
ALTER TABLE llx_mytable ADD CONSTRAINT fk_mytable_fk_field FOREIGN KEY (fk_field) REFERENCES llx_matablepere (rowid);
−
</source>
+
</syntaxhighlight>
−
==Table and fields structures==
+
==Tabellen- und Feldstrukturen==
*Structure of tables.
*Structure of tables.
Line 271:
Line 273:
When doing select, we can use alias to simplify writing/reading of requests:
When doing select, we can use alias to simplify writing/reading of requests:
−
<source lang="sql">
+
<syntaxhighlight lang="sql">
select chp1, chpxxx2 as chp2 from table2 as t1, table2 as t2 where t1.chpx = t2.chpy
select chp1, chpxxx2 as chp2 from table2 as t1, table2 as t2 where t1.chpx = t2.chpy
−
</source>
+
</syntaxhighlight>
However, we must not used alias for update request as they are not compatible with Mysql 3.1.
However, we must not used alias for update request as they are not compatible with Mysql 3.1.
*Using SELECT * is forbidden ! When using SELECT you must define complete list of fields to get. This avoids confusion. And above all, this make reengeering of code easier and make impact analysis of change on a field possible. Example:
*Using SELECT * is forbidden ! When using SELECT you must define complete list of fields to get. This avoids confusion. And above all, this make reengeering of code easier and make impact analysis of change on a field possible. Example:
−
<source lang="sql">
+
<syntaxhighlight lang="sql">
SELECT field_a, field_b, field_c FROM table_1 WHERE field_d = '$id'
SELECT field_a, field_b, field_c FROM table_1 WHERE field_d = '$id'
−
</source>
+
</syntaxhighlight>
*Into SQL requests, you must quote fields except the fields that contain amounts which must be stored as double or real type. Quotes on numbers may result in saving as a different value. For example 412.62 in an insert will be saved as value 412.61999512 into database (due to implicit conversion string to numeric) if the target field has type double(24,8). Only PHP see value 412.61999512. Other tools will see 412.62 giving a sense that there is no problem. But it's PHP that has the good vision. There is really a wrong value into database. By removing quotes on numbers, no problem occurs.
*Into SQL requests, you must quote fields except the fields that contain amounts which must be stored as double or real type. Quotes on numbers may result in saving as a different value. For example 412.62 in an insert will be saved as value 412.61999512 into database (due to implicit conversion string to numeric) if the target field has type double(24,8). Only PHP see value 412.61999512. Other tools will see 412.62 giving a sense that there is no problem. But it's PHP that has the good vision. There is really a wrong value into database. By removing quotes on numbers, no problem occurs.
Example:
Example:
−
<source lang="sql">
+
<syntaxhighlight lang="sql">
Good: INSERT INTO table_1 (field_txt, field_num) VALUES ('txt', 412.62)
Good: INSERT INTO table_1 (field_txt, field_num) VALUES ('txt', 412.62)
Bad: INSERT INTO table_1 (field_txt, field_num) VALUES ('txt', '412.62')
Bad: INSERT INTO table_1 (field_txt, field_num) VALUES ('txt', '412.62')
−
</source>
+
</syntaxhighlight>
Note, problem of float numbers is same problem on all langauges and not only when inserting data into database. It occurs also with any language when you work on "real" numbers, so numbers must be, as soon as they are affected, cleaned with function price2num with second parameter defined to :
Note, problem of float numbers is same problem on all langauges and not only when inserting data into database. It occurs also with any language when you work on "real" numbers, so numbers must be, as soon as they are affected, cleaned with function price2num with second parameter defined to :
Line 296:
Line 298:
For example, don't do:
For example, don't do:
−
<source lang="php">
+
<syntaxhighlight lang="php">
$sql="SELECT rowid FROM table where datefield = NOW()";
$sql="SELECT rowid FROM table where datefield = NOW()";
−
</source>
+
</syntaxhighlight>
but do:
but do:
−
<source lang="php">
+
<syntaxhighlight lang="php">
$sql="SELECT rowid FROM table where datefield = '".$this->db->idate(dol_now())."'";
$sql="SELECT rowid FROM table where datefield = '".$this->db->idate(dol_now())."'";
−
</source>
+
</syntaxhighlight>
For example, don't do:
For example, don't do:
−
<source lang="php">
+
<syntaxhighlight lang="php">
$sql="SELECT rowid FROM table where DATEDIFF(table.datefield, NOW()) > 7";
$sql="SELECT rowid FROM table where DATEDIFF(table.datefield, NOW()) > 7";
−
</source>
+
</syntaxhighlight>
but do:
but do:
−
<source lang="php">
+
<syntaxhighlight lang="php">
$sql="SELECT rowid FROM table where datefield < '".$this->db->idate(dol_now() - (7 * 24 * 3600))."'";
$sql="SELECT rowid FROM table where datefield < '".$this->db->idate(dol_now() - (7 * 24 * 3600))."'";
−
</source>
+
</syntaxhighlight>
An other advantage of this rule, is that request benefits of index because we are making a compare of a field with a fixed value. When using datediff, you make an operation on field before comparison, this means database can't use the index on field, resulting on very bad performance compared to solution without the datediff.
An other advantage of this rule, is that request benefits of index because we are making a compare of a field with a fixed value. When using datediff, you make an operation on field before comparison, this means database can't use the index on field, resulting on very bad performance compared to solution without the datediff.
Line 335:
Line 337:
To activate it (required when developing on Dolibarr), add the following line into the config file of your Mysql server (my.cnf or my.ini)
To activate it (required when developing on Dolibarr), add the following line into the config file of your Mysql server (my.cnf or my.ini)
−
<source lang="ini">
+
<syntaxhighlight lang="ini">
sql-mode="STRICT_ALL_TABLES,ONLY_FULL_GROUP_BY,NO_ZERO_DATE"
sql-mode="STRICT_ALL_TABLES,ONLY_FULL_GROUP_BY,NO_ZERO_DATE"
−
</source>
+
</syntaxhighlight>
==PostgreSQL specificities==
==PostgreSQL specificities==
Line 346:
Line 348:
MySQL Syntax:
MySQL Syntax:
−
<source lang="sql">
+
<syntaxhighlight lang="sql">
UPDATE table_taget as target, table_source as source SET fieldtarget=source.fieldsource
UPDATE table_taget as target, table_source as source SET fieldtarget=source.fieldsource
WHERE source.rowid=target.rowid;
WHERE source.rowid=target.rowid;
−
</source>
+
</syntaxhighlight>
PgSQL Syntax:
PgSQL Syntax:
−
<source lang="sql">
+
<syntaxhighlight lang="sql">
UPDATE table_taget as target SET fieldtarget=source.fieldsource
UPDATE table_taget as target SET fieldtarget=source.fieldsource
FROM table_source as source WHERE source.rowid=target.rowid;
FROM table_source as source WHERE source.rowid=target.rowid;
−
</source>
+
</syntaxhighlight>
There is no native SQL requests "UPDATE FROM" in all Dolibarr core. But if you use one in your own code of your module, you should do :
There is no native SQL requests "UPDATE FROM" in all Dolibarr core. But if you use one in your own code of your module, you should do :
−
<source lang="php">
+
<syntaxhighlight lang="php">
if ($this->db->type=='pgsql') {
if ($this->db->type=='pgsql') {
$sql="UPDATE table_taget as target SET fieldtarget=source.fieldsource
$sql="UPDATE table_taget as target SET fieldtarget=source.fieldsource
Line 366:
Line 368:
WHERE source.rowid=target.rowid";
WHERE source.rowid=target.rowid";
}
}
−
</source>
+
</syntaxhighlight>
=HTML norms=
=HTML norms=
Line 376:
Line 378:
For example:
For example:
−
<source lang="php">
+
<syntaxhighlight lang="php">
print '<a href="'.dol_buildpath('/mydir/mypage.php').'">'.img_picto('Texte alt','namepictopng','').'</a>';
print '<a href="'.dol_buildpath('/mydir/mypage.php').'">'.img_picto('Texte alt','namepictopng','').'</a>';
−
</source>
+
</syntaxhighlight>
*HTML tables must have columns with no forced width, except for columns that contains data we know the length. For example, a column with a picto only can be forced to with="20px".
*HTML tables must have columns with no forced width, except for columns that contains data we know the length. For example, a column with a picto only can be forced to with="20px".
Line 386:
Line 388:
*Javascript/ajax code and call to javascript files into php pages must be avoided. However, if you need to include javascript code, you must add a condition on "$conf->use_javascript_ajax"
*Javascript/ajax code and call to javascript files into php pages must be avoided. However, if you need to include javascript code, you must add a condition on "$conf->use_javascript_ajax"
−
<source lang="php">
+
<syntaxhighlight lang="php">
if ($conf->use_javascript_ajax) {
if ($conf->use_javascript_ajax) {
... // php code generating javascript here
... // php code generating javascript here
}
}
−
</source>
+
</syntaxhighlight>
*Popup windows must not be used, except for tooltips (and must have a condition as explained before).
*Popup windows must not be used, except for tooltips (and must have a condition as explained before).
Line 449:
Line 451:
With PHP, like other languages (Java for exemple), non integer data (float, real, double) are not reliable for calculation.
With PHP, like other languages (Java for exemple), non integer data (float, real, double) are not reliable for calculation.
Try to make for example
Try to make for example
−
<source lang="php">
+
<syntaxhighlight lang="php">
print 239.2 - 229.3 - 9.9;
print 239.2 - 229.3 - 9.9;
−
</source>
+
</syntaxhighlight>
You wont get zero but a very small decimal number. If you get zero her, you should be able to find other examples that don't work.
You wont get zero but a very small decimal number. If you get zero her, you should be able to find other examples that don't work.
Problem of float is general, so a variable that is a result of a calculation using decimal numbers must ALWAYS be cleaned using the function '''price2num()''' with the econd parameter to: 'MU', 'MT' or 'MS' depending on need (see description of function).
Problem of float is general, so a variable that is a result of a calculation using decimal numbers must ALWAYS be cleaned using the function '''price2num()''' with the econd parameter to: 'MU', 'MT' or 'MS' depending on need (see description of function).
−
<source lang="php">
+
<syntaxhighlight lang="php">
print price2num(239.2 - 229.3 - 9.9, 'MT');
print price2num(239.2 - 229.3 - 9.9, 'MT');
−
</source>
+
</syntaxhighlight>
If data manipulated is not an amount, then using MU, MT, MS has no sense, and you must use the function '''round()'''.
If data manipulated is not an amount, then using MU, MT, MS has no sense, and you must use the function '''round()'''.
Line 465:
Line 467:
==Comparing version==
==Comparing version==
If your code need to make different things depending on Dolibarr version, you can use the following tip to detect and compare versions
If your code need to make different things depending on Dolibarr version, you can use the following tip to detect and compare versions
−
<source lang="php">
+
<syntaxhighlight lang="php">
$version=preg_split('/[\.-]/',DOL_VERSION);
$version=preg_split('/[\.-]/',DOL_VERSION);
if (versioncompare($version,array(5,0,-4)) >= 0) { //mycode for 5.0 only; } // For dolibarr 5.0.* (the -4 means we include also alpha, beta, rc and rcX)
if (versioncompare($version,array(5,0,-4)) >= 0) { //mycode for 5.0 only; } // For dolibarr 5.0.* (the -4 means we include also alpha, beta, rc and rcX)
−
</source>
+
</syntaxhighlight>
But this solution need to include the function versioncompare. An alternative solution to test version is to do:
But this solution need to include the function versioncompare. An alternative solution to test version is to do:
−
<source lang="php">
+
<syntaxhighlight lang="php">
if ((float) DOL_VERSION >= 5.0) { //mycode for 5.0 only; } // For dolibarr 5.0.*
if ((float) DOL_VERSION >= 5.0) { //mycode for 5.0 only; } // For dolibarr 5.0.*
−
</source>
+
</syntaxhighlight>
==Logs==
==Logs==
Add logs to your code using function
Add logs to your code using function
−
<source lang="php">
+
<syntaxhighlight lang="php">
dol_syslog($yourmessage, LOG_INFO|LOG_DEBUG|LOG_WARNING|LOG_ERR);
dol_syslog($yourmessage, LOG_INFO|LOG_DEBUG|LOG_WARNING|LOG_ERR);
−
</source>
+
</syntaxhighlight>
==Working directory==
==Working directory==
Line 486:
Line 488:
The directory can be created into your code by the following function:
The directory can be created into your code by the following function:
−
<source lang="php">
+
<syntaxhighlight lang="php">
$mymoduledir=DOL_DATA_ROOT.'/mymodule';
$mymoduledir=DOL_DATA_ROOT.'/mymodule';
dol_mkdir($mymoduledir);
dol_mkdir($mymoduledir);
−
</source>
+
</syntaxhighlight>
If you need a directory to store temporary data, this directory must be '''DOL_DATA_ROOT.'/mymodule/temp''''
If you need a directory to store temporary data, this directory must be '''DOL_DATA_ROOT.'/mymodule/temp''''
Line 534:
Line 536:
*The '''Table And Row Data Gateway'''
*The '''Table And Row Data Gateway'''
−
This is the most simple. You have one class per table and each class is a link to the table with CRUD methods (Ceate, Read, Update, Delete). A class instance is a record in the table. The class contains only code to reach lines and fields of table.
+
This is the most simple. You have one class per table and each class is a link to the table with CRUD methods (Create, Read, Update, Delete). A class instance is a record in the table. The class contains only code to reach lines and fields of table.
Example: This mode is used by some ORM Frameworks, like '''iBatis''' (http://ibatis.apache.org/).
Example: This mode is used by some ORM Frameworks, like '''iBatis''' (http://ibatis.apache.org/).
Line 549:
Line 551:
More "purist" on paper (closer of business), this method also has the disadvantage of being more complex in practice.
More "purist" on paper (closer of business), this method also has the disadvantage of being more complex in practice.
−
Example: This is the choice if you use the ORM Framework '''Propel''' (http://propel.phpdb.org/trac/). We find this model in heavier applications, based on this ORM among others.
+
Example: This is the choice if you use the ORM Framework '''Propel''' (https://propelorm.org/). We find this model in heavier applications, based on this ORM among others.
−
-> For Dolibarr development, it is recommended to use the connection mode '''Active Record''', which offers the advantages of a model close to the business without having the complexity, without obfuscating technical architecture. It is by this way that the development, understanding of code and technical maintenance and / or business behaviour seems the more productive (this is however an ongoing debate between the purists and the pragmatists, debate in which nobody can really be right, because it depends on the objectives).
+
-> For Dolibarr development, it is recommended to use the connection mode '''Active Record''', which offers the advantages of a model close to the business without having the complexity, without obfuscating technical architecture. It is by this way that the development, understanding of code and technical maintenance and / or business behavior seems the more productive (this is however an ongoing debate between the purists and the pragmatists, debate in which nobody can really be right, because it depends on the objectives).
−
[[Category:Development]]