31,003
edits
| Line 32: | Line 32: | ||
Launch Dolibarr and go to page '''Setup->module'''? You must see a new line with your new module and the possibility to activate it or not (browse all the tabs of each category of modules to find it). It's value of $this->special that determines in which tab will be your module. | Launch Dolibarr and go to page '''Setup->module'''? You must see a new line with your new module and the possibility to activate it or not (browse all the tabs of each category of modules to find it). It's value of $this->special that determines in which tab will be your module. | ||
= | = Create your SQL tables and the PHP accessor class (optionnal) = | ||
''' | '''When''': If your module needs to manage data of its own | ||
== | == Create your .sql file == | ||
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. | |||
Files 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. Then in the "load_tables" function of your file descriptor module, modify the line | |||
<pre>$dir = DOL_DOCUMENT_ROOT.'/mymodule/sql/';</pre> | <pre>$dir = DOL_DOCUMENT_ROOT.'/mymodule/sql/';</pre> | ||
by | |||
<pre>$dir = DOL_DOCUMENT_ROOT.'/ | <pre>$dir = DOL_DOCUMENT_ROOT.'/valuechooseformymodule/sql/';</pre> | ||
''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 '''mysql/tables''' for examples). | |||
* To manage data, you must create a file called '''data.sql''' inside directory '''/mymodule/sql/''' that contains SQL command to add/edit/delete datas. | |||
Example of content of a file data.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__'; | ||
insert into llx_const (name, value, type, note, visible, entity) values ('MYMODULE_IT_WORKS','1','chaine','A constant vor my module',1,'__ENTITY__'); | insert into llx_const (name, value, type, note, visible, entity) values ('MYMODULE_IT_WORKS','1','chaine','A constant vor my module',1,'__ENTITY__'); | ||
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. | |||
Rem: | |||
== | == Test your .sql files == | ||
Une fois les fichiers prêts, vous pouvez retourner sous Dolibarr puis désactiver le module, dropper les tables en base et réactiver le module. | Une fois les fichiers prêts, vous pouvez retourner sous Dolibarr puis désactiver le module, dropper les tables en base et réactiver le module. | ||