ObjectExplorer Snippet Tutorial
If you use this extra and like it, please consider donating. The suggested donation for this extra is $5.00, but any amount you want to give is fine (really). For a one-time donation of $50.00 you can use all of my non-premium extras with a clear conscience.
ObjectExplorer displays information about the various objects in the MODX Revolution database. Its output is derived from the MODX schema file, so it will display the current information for the version of MODX you are using.
Fully updated for MODX 3 and PHP 8
Installing ObjectExplorer for MODx Revolution
Go to Extras > Installer Management on the main menu in the MODx Manager and click on the "Download Extras" button. That will take you to the Revolution Repository. Put ObjectExplorer in the search box and press Enter. Click on the "Download" button. When the download is finished, click on the "Back to Package Management" button. That should bring you back to your Package Management grid. Click on "Install" next to ObjectExplorer.
Usage
To execute ObjectExplorer, just create a new resource to display the output and put a snippet tag for it in the Resource content field:
[[ObjectExplorer]]
This tag is equivalent to the one above and can be used if you want to use a template variable to set the type of display, create the display dynamically based on user input, or call ObjectExplorer with runSnippet():
[[ObjectExplorer? &full=`0` ]]
If you set &full=`1`
, you'll see a more complete display. The complete display contains more information, but it's more difficult to read.
As of Version 1.2.0-pl, there is also an option to display the MODX 3 schema on a MODX 2 site using the following property:
[[ObjectExplorer? &show_modx3=`1` ]]
Do *not* use the property above on a MODX 3 site, because it will show you the MODX 3 schema packaged with ObjectExplorer (which may be out of date) instead of the real one.
Display
By default, ObjectExplorer will display a quick reference to the MODX objects in alphabetical order. This is the recommended display because it contains the fields of the objects (including inherited fields), the aliases of related objects, how to use those aliases and what they return. The full display is more detailed, but it doesn't show inherited fields and is much less useful.
You may have to alter the CSS file to work with your template.
Although the quick reference contains most of the information you might want and is generally more useful, it does leave some things out, such as the types of the aliases (aggregate or composite) and the default values of the fields. If you would like a full dump of the schema as an array, use this tag instead:
[[ObjectExplorer? &full=`1`]]
ObjectExplorer Properties
Property | Description | Default |
---|---|---|
full | (optional) display full version of schema | 0 |
columns | (optional) Sets the number of columns in the jumplist at the top of the display | 2 |
show_modx3 | (optional) Parses a local copy of the MODX 3 schema on MODX 2 sites. Do not use for MODX 3 sites! | 0 |
If you change the number of columns, you'll probably need to change the width of #objectexplorer_jumplist_div in the objectexplorer.css file.
Other Uses
The snippet code can be run outside of MODX if you would like to produce output on your local machine for reference or pasting. To do that successfully, you'll need to modify the path information near the top of the code. If you want the full display (as opposed to the quick display), you'll also need to set the $props['full'] variable to 1.
The ObjectExplorer class can also be used to display information on a single MODX object. To do that:
- copy the code at the top of the snippet that creates the classes
- call $explorer->parseSchema($model)
- set $objectName to the name of any MODX object (e.g., modResource, modChunk)
- call either $explorer->getQuickSingle('objectName')
- or $explorer->getFullSingle('objectName')
- return the result of that call
My book, MODX: The Official Guide - Digital Edition is now available here. The paper version of the book may still be available from Amazon.
If you have the book and would like to download the code, you can find it here.
If you have the book and would like to see the updates and corrections page, you can find it here.
MODX: The Official Guide is 772 pages long and goes far beyond this web site in explaining beginning and advanced MODX techniques. It includes detailed information on:
- Installing MODX
- How MODX Works
- Working with MODX resources and Elements
- Using Git with MODX
- Using common MODX add-on components like SPForm, Login, getResources, and FormIt
- MODX security Permissions
- Customizing the MODX Manager
- Using Form Customization
- Creating Transport Packages
- MODX and xPDO object methods
- MODX System Events
- Using PHP with MODX
Go here for more information about the book.
Thank you for visiting BobsGuides.com
— Bob Ray