Order of execution
From MODx Wiki
[edit]
Introduction
MODx delivers a page by returning the output of an object. As a developer, you may find it useful in understanding what order this process is executed in.
This information is relevant for MODx 0.9.1-0.9.5.
The future of MODx holds many significant and beneficial changes. To quote one of our founding fathers, OpenGeek:
"That's fine to post this kind of stuff in the wiki; but, keep in mind, the changes coming down the pipe are going to significantly change this internal processing model." -- OpenGeek
Remember that clear planning should make transition into the as of yet unfinished specification of MODx 1.0 a trivial task. Please develop your applications with this in mind while using the guide below.
[edit]
Order of Execution
- index.php initiates an "output buffer" (ob_start) object, and a new DocumentParser object called $modx.
- index.php calls $modx->executeParser().
- Parser gets site settings ($modx->config array, such as $modx->config['site_name']).
- Parser checks site's available status and outputs the unavailable page or message if site is unavailable. Done.
- Parser unpublishes/publishes all documents that need to be published/unpublished at this time.
- Parser determines from the URL request how to get the page to be parsed (site_start? alias? docID?) and works out the ID of the document it wants.
- Parser invokes the OnWebPageInit event at this point.
- Parser invokes the OnLogPageHit event, if track_visitors is set to 1.
- Parser checks cache, if page is cached loads the cache file into $modx->documentContent and invokes the OnLoadWebPageCache event, and jumps straight to the outputContent function without further parsing.
- Parser calls getDocument object, which goes through various access checks, and loads the $modx->documentObject array (such as $modx->documentObject['pagetitle']). It also adds the TV tags from the document's template to the documentObject.
- Parser determines if page is published, and if not, if the user has permissions to view unpublished documents.
- Parser determines if page is a "reference" (weblink) and quits with a redirect if it is.
- Parser gets the document's template and sets the $modx->documentContent array to the template's content.
- Parser invokes the OnLoadWebDocument event (at this point you can see the template with all the MODx tags).
- Parser inserts metatags and keywords.
- Parser sets $modx->documentOutput to documentContent (still only the template, no tags parsed yet) and records its length (to see if it needs another pass).
- Parser invokes the OnParseDocument event.
- Parser merges the document's content into documentOutput (the [*content*] tag). As far as I can tell, TVs are also parsed and merged at this time.
- Parser merges site settings tags into documentOutput (such as [(site_name)]) and calls parseDocumentSource with documentOutput as an argument.
- parseDocumentSource merges chunk content into documentOutput (any MODx tags in the chunk are passed through unchanged for the next pass to deal with).
- parseDocumentSource merges snippet output into documentOutput.
- parseDocumentSource merges placeholders into documentOutput.
- parseDocumentSource checks length of documentOutput, and if it has changed, runs it through parseDocumentSource again (up to maxParserPasses). When either the length doesn't change, or maxParserPasses is reached, the documentOutput is returned to the parser.
- Parser inserts any JavaScript or CSS blocks (regClientStarupScript(), etc).
- Parser sends documentOutput to outputContent function.
- outputContent deals with uncached snippet calls (coming from a cached document).
- outputContent runs through parseDocumentSource again (to parse these uncached snippet calls).
- outputContent deals with any more JavaScript or CSS blocks (in case the uncached snippet call had any).
- outputContent gets rid of any unused placeholder tags.
- outputContent rewrites any URLs in the content.
- outputContent sets up content-type and content-disposition headers.
- outputContent sets up the timing, number of queries values ([^q^], etc).
- outputContent invokes the OnWebPagePrerender event.
- outputContent echoes the final documentOutput and the buffer is flushed to the client (ob_end_flush).
- postProcess determines if the page should be cached, if yes, OnBeforeSaveWebPageCache is invoked and cache is saved.
- postProcess checks if visitor tracking is enabled, if yes, OnWebPageComplete is invoked and php shuts down.
[edit]
Credits
Thank you to Sottwell for the time you have spent tinkering with this app and understanding how it works.
- Matthew Pietz 11:18, 3 January 2007 (PST)
- ScottyDelicious 12:07, 12 November 2006 (PST)
