Modules are how you would extend the back-end.
I am currently in the process of creating a module for controlling a glossary database that can be accessed read-only by certain Web users from the front-end, and managed from a module. Basically, the module is much like a snippet.
The output of the module is in the right-hand panel of the Manager, just like the built-in functions. I use that as my interface, and otherwise write the application as I would any other PHP application, including files and classes and whatever else I need, into the main module. All of the include files are stored in a folder in the /assets/modules/ folder.
All of the MODx API is available, so a lot of the work is already done as far as document manipulation goes.
So far, this is my module code:
$basePath = $modx->config['base_path'];
// If we cant't find the module files...
if(!file_exists($basePath.$mod_path)) {
// Log an error
$error_message = '<strong>Glossary module not found!</strong></p><p>Edit the Glossary module, click the Configuration tab and change the Module Path to point to the module.</p>';
$modx->Event->alert($error_message);
$modx->logEvent(0, 3, $error_message, 'Glossary');
} else {
$GLOBALS['glossary_path'] = $mod_path;
// include the language file
include($basePath.$mod_path.'/langs/en.php');
// if Browse or Search
if(!empty($_POST) && isset($_POST['browse']) || isset($_POST['search'])) {
include($basePath.$mod_path.'/mutate_termbase.dynamic.action.php');
} else {
include($basePath.$mod_path.'/manage_termbase.dynamic.action.php');
}
}
The $mod_path variable is set in the Configuration of the module:
&mod_path=Module Path (from site root);string;assets/modules/glossary
I wrote my include files to mimic the existing manager action and processor files. For example, the main manage_termbase file has (along with some functions and other stuff) this:
<html>
<head>
<title>termbase</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="media/style/style.css?" />
<link rel="stylesheet" type="text/css" href="media/style/coolButtons2.css?>" />
<style>
body {
overflow-x : hidden; /* stupid hack for equally stupid MSIE */
}
</style>
</head>
<body>
<div class="subTitle">
<span class="right"><?php echo $_lang['manage_termbase']; ?></span>
</div>
So it uses the same css files and button and background images as the rest of the Manager.
Otherwise, it works just like any php application works. I can determine who can run it by what manager user groups it is assigned to.
The method used in the Manager to run modules is a little obscure at this time; I’m sure it will be improved in future releases.