Module development: Difference between revisions

Jump to navigation Jump to search
m
Tag: 2017 source edit
Tag: 2017 source edit
Line 109: Line 109:


===Generate the PHP DAO class===
===Generate the PHP DAO class===
Once you have created your tables into the database, move to the dev/skeletons directory and run the script
The PHP files should also have been created by ModuleBuilder.


<syntaxHighlight lang="bash">php build_class_from_table.php tablename modulename</syntaxHighlight>
You can however create them manually by copying existing object however using ModuleBuilder is highly recommended.
Note: If the command does not work, try to use php-cli php instead.
 
This will generate a file '''out.tablename.class.php''' that contains the class to manage table tablename.
In this class, you can find the CRUD methods (Create / Read / Update / Delete) already working to do an insert, a fetch (select), an update, a delete of a row in table.
Remove just the "out" from the file name and put the file in a subdirectory of '''htdocs''' specific to your module (in htdocs/mymodule for example).
 
A file '''out.tablename_script.php''' has been generated and contains a sample code to use the class for each of the 4 CRUD methods.
 
'''Since Dolibarr 6.0, the file dev/skeletons/build_class_from_table.php is no more provided. To build a class from a table you should use the ModuleBuilder modules provided as a standard module.'''


==The tab management (optional)==
==The tab management (optional)==

Navigation menu