modX.getInstance
Last updated not available | Page history | Improve this page | Report an issue
Support the team building MODX with a monthly donation.
The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.
Backers
Budget
$194 per month—let's make that $500!
Learn moremodX::getInstance¶
Create, retrieve or update modX instances. This is the standard way to get a modX object: every MODX entry point uses it and registers the result in the shared instance registry.
Syntax¶
static modX getInstance ([string|int|null $id = null], [array|null $config = null], [boolean $forceNew = false])
-
$id(string|int|null) Identifier of the instance. When omitted, the existing instance is returned if there is one; otherwise a new id is generated and a new instance is created. -
$config(array|null) Config data for the instance. Passing it with an$idthat already exists merges the values into that instance's config; passing it without an$idforces the creation of a new instance. -
$forceNew(boolean) Force the creation of a new instance even if one with the given$idalready exists.
Returns the modX instance; throws xPDOException if the registry entry is not a valid instance.
Registering matters: an object created with new \MODX\Revolution\modX() runs, but it is not stored in the registry. The next getInstance() call — from an entry point, setup or a test — then builds a second instance with its own database connection and config. Use getInstance() everywhere.
Example¶
Load MODX externally through the instance registry:
require_once '/absolute/path/to/modx/config.core.php';
require_once MODX_CORE_PATH . 'vendor/autoload.php';
$modx = \MODX\Revolution\modX::getInstance();
$modx->initialize('web');
See Also¶
Support the team building MODX with a monthly donation.
The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.
Backers
Budget
$194 per month—let's make that $500!
Learn more










