These rules should be applied by all development projects on this site:
Contents |
Reduced SQL query count
Great pains should be taken to reduce the amount of queries needed on a page. This means: No queries in xoops_version.php unless in current module
This means that if you use queries to determine submenu items in the main menu, first put a check to see if your module is current module with a
global $xoopsModule;
if (is_object($xoopsModule) && $xoopsModule->getVar('dirname') != $modversion['dirname']) {
No queries within loops
If you need information based on a previous query, loop through the results of the first query to find the items needed in the second query and retrieve all that information in one go.
e.g. instead of retrieving user information inside a loop of articles, first retrieve the articles, then find the userID's, you need, and then retrieve user information for the found userID's
Improve readability
Nobody likes to read a page full of complex processing and SQL queries
Place complex processing in functions or class methods
If you are doing complex processing, put it in a function or a class method with a descriptive name. If you should need the same processing done later, you have a handy function for it.
Place all SQL queries in functions or class methods
There should be no need for SQL queries outside functions or class methods. It greatly improves readability to have only descriptive calls to functions or class methods instead of SQL queries and subsequent going throught the resultset.
Use XOOPS Form library
Forms should be in included files, using the XoopsForm library. It is an easy way to have a form and will make it easier to modify and add elements to it.
Use of the $xoopsModule->getVar('dirname')
Don't hardcode your module dirname in your php files and templates. We can translate the module content, if you use this we can translate the module name too with a small change in the module's xoops_version.php (E.G. An Italian website doesn't needs a wordbook module, but it needs a 'dizionario' one) Since Xoops v. 2.0.10 a new smarty var is added in the core, <{$xoops_dirname}>, that return the module dirname so you can use this in your templates - if an absolute path is needed.
Use Templates
Can't be stressed enough. Templates complete the MVC separation of the code and is a very important part of making modules easy to understand.
You have tools - use them!
Back to the Main Page

![[Main Page]](/modules/mediawiki/images/mediawiki.png)






