Exploring MODx From the Inside: How MODx Works

How MODx Works

MODx works in two parts. One part parses resources and processes elements to generate dynamic web pages, while the other part provides the Manager interface and functions.

To begin with, we'll look at how MODx generates a dynamic web page.

How the MODx Parser Works

When a page request loads the front-end index.php file, the server includes either the ID or the alias of the resource being requested, depending on your site's configuration. The index.php file initializes the modx object and starts the parser.

The parser takes a number of steps to determine exactly what response goes back to the server:

When the final output is ready, MODx sends it to the server with a rather anti-climactic echo statement:

echo $this->documentOutput;

How the MODx Manager Works

When you request the manager/index.php page, the first thing it does is check to see if you are logged in, and displays the login form if you are not.

Once you are logged in, the manager/index.php page has a long list of possible actions to take. The requested actions are passed in the URL query string. The default action, which will be what happens when you first log in, is to display the Manager Home or Welcome page.

From that point, each menu item you select will request the manager/index.php page with its ID in the query string. The switch structure in the index.php file will include the appropriate .php file to display the content for the action you've selected in the right workspace frame.

When you save your work, a corresponding processor .php file is used to process the forms and return you to the appropriate Manager page.

Manager Templates

The Manager template is specified in the Configuration. The templates and supporting css and image files are stored in manager/media/style. MODx 1.0 Evolution has some of the manager pages that are most frequently customized (login.html, manager.lockout.html and welcome.html) in assets/templates/manager.

There are several manager templates available at the MODx Resources site. Some of these were designed for earlier versions of MODx, so make sure to check their version support. If you try one of these templates and it trashes your Manager, you'll need to go to the database and change the setting in the system_settings table for the manager_theme field.

Manager Theme

The default for 0.9.3 is MODxLight; for 1.0 Evolution it is MODxCarbon.

Manager Frames

Manager Frames

The Manager page has three frames. The code for these can be found in the manager/frames folder. The 1.php file contains the structure for the entire page.

Most of the elements are stored in the database. What is displayed in the editing fields for the element is taken from the database. Most of the elements also have a tab with fields for configuring the element. Some snippets, modules and plugins will have a minimum of initialization code in the database, while the rest of the code is in library or class .php files in the filesystem, usually in the assets/snippets, assets/modules and assets/plugins folders, and is included by the viewable code. All of the elements can be stored in files if this is preferred; how to do this will be explained in the section covering snippets.

The Manager also loads and starts up the parser, to enable it to use all of the library functions for accessing the database, user log-in status and the site configuration.

When you first install MODx, you are usually presented with the Configuration workspace. This can also be opened from the Tools -> Configuration menu item. There are several tabs for different sections of the configuration. Go through the Configuration and look at the various options. Most of them have a basic description of their purpose. To begin with, just set the Site Name to the name of the site. In the illustration below, I've used my domain name. That's not at all a requirement; I just couldn't think of a clever name for my site.

Set the Site Name

The settings from the configuration, which are stored in the system_settings table of the database, plus a few from the config.inc.php file that was created when you installed MODx, can be accessed in HTML by the [(fieldname)] tags, such as [(site_name)] . In PHP code, they can be accessed with

 $modx->config['fieldname']  

As with most of the actions in the workspace, you can save your changes by clicking on the Save Button button floating at the top of the workspace.

The MODx Manager Main Menu

Take a few minutes and go through the main menu and see what the different menu items offer.

Site

Site Menu

The Site menu has six items.

Elements

Elements Menu

The Elements menu offers two items.

Modules

Modules Menu

The Modules menu will have at least one item, Manage Modules. This allows you to create new modules or edit and enable/disable existing modules. Modules are the way to add extra functionality to the Manager without having to modify the core manager scripts. The Modules items will reflect all of the modules that are installed. By default MODx comes with the DocManager module pre-installed.

Security

Security Menu

The Security menu offers the various items for managing the users for your site, both front-end web users and Manager users. The MODx security system will be covered in depth later.

Tools

Tools Menu

The Tools menu provides a number of items for managing the site:

Reports

Reports Menu

The Reports menu offers items to provide information about your site.

Both the System Events and the Manager Actions are stored in the database, and occasionally should be checked and cleared if they are getting too big.

Comment On This Article

Do you find something unclear? Did I miss something or get something wrong? What do you like or not like about this chapter? Please do not ask for help here; use the forums if you need help.

If you have trouble reading the code, click on the code itself to generate a new random code.
Wed May 26, 2010, 04:30:03
Great!! It helps me so much
Wed January 06, 2010, 09:19:41
I agree with the last persons comment - excellent!
Sun December 27, 2009, 19:20:17
Congratulations - I am an absolute newbie to ModX and your site contains exactly the sort of information I'm looking for. (In fact it is one of the best "How To" sites I have ever come across!)

I look forward to your article on security and hopefully you will explain how to allow web users to add and edit their own content?

Geoff B
Tue June 23, 2009, 10:25:59
thanks for the summary it helps