Explanation of directory structure

Explanation of directory structure Getting Started

The MODX root directory is divided into several subdirectories, each with its own set of responsibilities and tasks. For clarity, you can download the distribution with the MODX traditional CMS and unpack it, you will see the following structure.

modx directories

Some of these directories can be renamed and moved, and their location can be changed during installation (MODX advanced), the assets directory is created during installation. Let’s look at all the main directories.

connectors/

The “connectors” directory contains connector files that are responsible for handling AJAX requests and interacting with other applications and services. Here you can set up a connection to external APIs or add your own scripts to work with data. The connectors do not perform any manipulations with the database themselves: they simply load the main MODX class, clear any request data, and then process the request by pointing to the appropriate processor file.

  • connectors/index.php is a particularly useful file when creating your own connectors. Simply include this file in your connectors and then handle the request using $modx->request->handleRequest();

core/

The “core” directory contains the core files and code of MODX Revolution. This is where the core of the system is located, responsible for handling requests, managing the database and working with extensions. Inside “core” you will also find subdirectories such as “config” for the system configuration and “model” for the database models. Most of everything you need, except for the manager files and installation files, is in this directory.

core/cache/

This directory contains all the cache files generated by MODX. Lexicons, resources, elements, RSS and Smarty data are all generated on demand by MODX, i.e. they are only cached after the first access.

core/cache/logs/

All files in MODX are logged here. Here you will find the error.log file, which contains the date, time, file, and error logged by MODX. To write an entry to this file, you can use the $modx->log() method.

core/cache/mgr/

This directory contains cache data for the mgr (Manager) context. Like any context cache, it will cache any context settings that have been overridden from their system defaults.

core/cache/rss/

A cache of every RSS feed in MODX.

core/cache/web/

Another cache directive that is split into several parts. Each context (ie. web and mgr) has a context.cache.php file. This file is similar to the config.cache.php file, except that it only caches settings that have been overridden from their system defaults. Any context can override a system setting. In addition, the web context cache will contain separate directories for resources and items. The resource with the ID 12 will be found in cache/web/resources/12.cache.php. This new caching mechanism means that load times will be reduced and the limit on the number of resources that can be cached will be removed.

core/components/

When you install a package using the Package Manager, a directory will be created in core/components/ to store any files needed to run the installed component. Typically, any files needed to run in the manager, such as controllers, schema model data, processors, and class files, should be stored here, as well as files that you do not need to be accessible from the web.

core/config/

This directory contains the configuration file for MODX Revolution. It sets up the database credentials and a number of MODX constants to make your site work properly.

core/docs/

This directory contains the changelog.txt file, the GPL license, and all the tutorials created for Revolution.

core/error/

It contains templates for error messages in the Revolution client. You can customize these pages here.

core/export/

After running the export feature in MODX Revolution, the exported HTML files for your site will be located here.

core/import/

To run the import feature in MODX Revolution, you need to move the HTML files to this directory.

core/lexicon/

Here are the language files (lexicons), which are separated into separate directories based on their two-letter IANA code (for example, English lexicons are stored in /core/lexicon/en/). Within these subdirectories are several files in the format topic.inc.php. A “topic” is simply a single lexicon file. Separating the lexicons by topic means that only the _required_language strings are loaded, saving memory and load time. All lexicons are stored in the MODX database and then cached on demand. This allows you to manage lexicons directly from the admin panel in the “Manage Lexicons” area. To load a lexicon, you can use this format:

$modx->lexicon->load( 'lang:namespace:topic' );

lang – 2-digit IANA code. This is optional and defaults to ‘en’.

  1. namespace – Each lexicon has its own Namespace. The built-in namespace for MODX is “core”. Package creators will also be able to create their own namespaces, and Manager users can also create their own namespaces.
  2. topic – The specific topic/file you want to load.

core/model/

This is the Model: the M in MVC (Model-View-Controller), which is an OO paradigm that states that an application should have at least three parts. The Model, which contains the database structure and bindings to it, the View, which is the GUI part of the application that doesn’t contain any logic – just the presentation; and the Controllers, which connect the Model to the View. So MODX does the Model kind of similar. We’re actually doing an MVC/C model where we add a Connector access point and Processors to the Model. This will be explained later when we come to them. What you need to know now is that the model contains all the PHP classes that run Revolution, including processors that handle specific functions like saving snippets, deleting snippets, etc.

core/model/modx/

Here are classes that are either xPDOObjects – which are PHP classes that represent tables in the database (i.e. modsnippet.class.php is a PHP class that is an object of modx_site_snippets), or they are functional classes, like modcachemanager.class.php. The subdirectories in this folder – not including mysql or processors – are subcategories of classes that are loaded like this: $modx->loadClass('transport.modPackageBuilder'); with “.” being the directory separator.

core/model/modx/mysql/

This directory contains the class and map files for each xPDO object. Maps are simply PHP arrays containing the structure of the database table they reference. Other database platforms such as pgsql, mssql, and others will also appear here.

core/model/modx/processors/

This directory contains the individual processor files used in database manipulation. They are never accessed directly, but instead are accessed through connectors. This allows them to be locked down to prevent unauthorized access.

core/model/schema/

The schema is an XML representation of the MODX database. This is used when creating new maps and classes, but is never read or parsed when MODX is running. For the most part, you can ignore this directory, as it is primarily used for development.

core/model/smarty/

This contains the Smarty libraries, an intelligent object-oriented templating engine that uses dynamic, modifiable placeholders. Most of the pages you see in the Manager and during installation are Smarty template files (.tpl) that MODX interacts with. For example, when you edit a resource (often a document) in the Manager, you view the controller-generated page in manager/controllers/resource/staticresource/update.php After setting the resource properties in the $resource array, this code displays the page:

$modx->smarty->assign('resource',$resource); return $modx->smarty->fetch('resource/staticresource/update.tpl');

The Smarty placeholders in update.tpl are populated with the data stored in the $resource array.

core/packages/

Here you will find any transport packages you have downloaded via the Package Manager section of Revolution, such as Ace, TinyMCE, PdoTools, etc. The core package is also located here. This allows for easy installation and removal, as well as remote updating of installed packages. When you create a package (for example after pulling from Git), the transport package will be stored here.

core/xpdo/

MODX Revolution was designed to use OpenExpedio (xPDO), an extension to PDO. It provides a unified interface for managing databases and allows MODX to support multiple database platforms other than MySQL. This directory contains all the class files xPDO needs to do everything from caching queries to building transport packages and outputting data as a convenient JSON object. These classes are used internally by MODX and developers should never have to deal with them directly.

Some Files

  • core/cache/config.cache.php – This is the cache file for all System Settings in MODX. Their database equivalents are in the _system_settings table, and their xPDO equivalents are modSystemSetting objects.
    • Tip – If you’ve ever been blocked by the CAPTCHA component, you can edit this file and set use_captcha to ‘0’ to disable captcha. You can then go in and disable CAPTCHA in System Preferences.
  • core/cache/sitePublishing.idx.php – This file keeps track of cache refresh intervals.

manager/

The manager is the backend or admin area of ​​MODX for creating assets, managing users, and performing general site maintenance tasks.

manager/assets/

This directory contains the ExtJS libraries, as well as a custom implementation of ModExt. ModExt extends the original ExtJS library to make development more user-friendly.

manager/controllers/

Controllers are PHP files that generate Manager pages. They simply retrieve data and return or output it to the browser for rendering and display. Whenever you load a page in the Manager, you are essentially telling MODX to load a specific Controller, which simply loads a Smarty template and outputs any necessary JavaScript to the browser.

manager/templates/

This directory contains the template files for each Manager page. These do not contain PHP code, but are used to organize the HTML. If you are looking for the Smarty .tpl file for a specific Manager page, check the manager/templates/default/ directory.

Notable Files

  • manager/assets/ext2/ext-all.js – This is the core Ext library file that should be included on all Manager pages (or any page that uses Ext). It is compressed to save space, reduce download times, and speed up page load times. However, if you do a lot of JavaScript work, you will inevitably run into some cryptic errors due to compression. The best way to deal with this is to simply rename this file, and then rename the ext-all.js file to ext-all-debug.js to use the uncompressed version during development. Just be sure to switch them later!

setup/

This directory contains the files needed to run the engine installer: installing MODX or updating it.

_build/

This directory is only present in the version of MODX Revolution downloaded from the Subversion server (as well as in the SDK distribution). It contains the packed MODX core data files needed to install MODX into the database.

  • _build/transport.core.php – This file must be executed after downloading MODX Revolution and before running the installer. Once complete, you should replace the “core” directory inside your core/packages/ directory, which will contain all the necessary Vehicles for installing MODX Revolution.

assets/

This directory is not present by default in MODX Revolution, but is typically where images, CSS, JavaScript, and other media files are placed.

assets/components/

When you install a package using the Package Manager, a directory will be created in the assets/components/ directory to store any necessary component files, such as JavaScript or images. Being familiar with this structure will allow developers to more quickly understand the intricacies of MODX programming (creating packages and various custom solutions) and ensure more efficient development and support of a project on MODX Revolution. See also: MODX Glossary

Rate article
MODX 3
Add a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.