Gossamer Forum
Home : Products : DBMan : Customization :

one html.pl for multiple db configs

Quote Reply
one html.pl for multiple db configs
I don't know whether the following has been done before, but it might be useful to some:

Imagine three databases db1, db2, db3, each with their own db1html.pl, db2html.pl, and db3html.pl. Now, it turns out that only $html_title and the subroutines html_record and html_record_form vary in these three files - the rest is the same. Hence the plan: create one common hmtl.pl with all the subs except for these two, plus the declaration of $html_title, which are taken out and stored in individual files called db1config.pl, db2config.pl, and db3config.pl. The following changes refer specifically to db1. Do the same for db2 and db3.

1) To the newly created db1config.pl, add require $db_script_path . "/html.pl";
2) To db1.cfg, add $db_configfile = "$db_script_path . "/db1config.pl";
3) To db1.cfg, add require $db_configfile;
4) Lastly, to html.pl, add require $db_configfile; [Steps 3) and 4) are necessary to keep html.pl REALLY common for all dbs.]

This makes setting up new dbs much easier: You only have to edit db.cfg and to customize html_record and html_record_form in db1config.pl. Needless to say, you can also do this when you find that other parts of html.pl - only minimal ones - than html_record or html_record_form vary, whereas the bulk of code remains the same.





kellner