Aspects
Two very important objects need to be understood in order to write a module for XOOPS: $xoopsUser and XoopsDB
Anatomy of a Module Page
A module file, which should be accessed via a browser URL (i.e. not files which will always be included in other files) should be in the modules/modulename folder.
The first thing a module page should do is include the root file "mainfile.php". Mainfile.php includes include/common.php which will:
Setup the connection to the database Login the user if not anonymous Include the XOOPS API functions Retrieve the current module ($xoopsModule) Retrieve the module's configuration options ($xoopsModuleConfig) Include relevant language files Checks that the site is not closed - or if it is, that the user can access it Checks if the user has access to the current module
After the inclusion of mainfile.php, the module page should process anything necessary to decide on the template to be used - provided the page uses Smarty templates - with
$xoopsOption['template_main'] = "template_name.ext";
The next step is to include the root file header.php, which will:
Create the Smarty object, $xoopsTpl (Note: From 2.2, this is done in include/common.php) Check the page cache settings and either display the cached page or build the blocks to be displayed on the page
Note: If $xoopsOption['template_main'] is not set prior to the inclusion of header.php, the page cache will not kick in.
Now that the main parts of XOOPS have been included, the file can process the data to be shown on the page and assign variables to Smarty - if applicable. This can be any php code and as such doesn't have to be related to XOOPS although it should of course use the XOOPS core functionality where appropriate.
Here, $xoopsOption['output_type'] can also be set to "plain" if the page is to be displayed without any non-module content (like header, banner and blocks - usable e.g. in popup windows) - in which case the inclusion of header.php serves solely to check the page cache.
The file should end with including the root file footer.php, which will display the theme's theme.html with the blocks and module content retrieved earlier.
Note: Not including footer.php in a page using Smarty will result in a blank page with no content and no related error messages. If the page is not using Smarty, only the page's own content will be displayed without blocks, headers, footers and without the theme being applied.
Anatomy of a module Administration page
Admin pages should be in the modules/modulename/admin folder and have this structure:
include ('../../../include/cp_header.php'); xoops_cp_header();
//Module admin code similar to a frontside module page (Note: Before XOOPS 2.2, $xoopsTpl could not be used directly in the administration area, but would have to be manually instantiated or HTML output directly in the PHP files)
xoops_cp_footer();
Back to Main Page

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






