xPDO.loadClass
Last updated Apr 20th, 2021 | 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
$185 per month—let's make that $500!
Learn more⚠️ DEPRECATED – xPDO::loadClass¶
Note: loadClass() has been deprecated since xPDO 3.0. Use Composer autoloading or addPackage() with PSR‑4 instead.
xPDO::loadClass¶
Include a class by fully qualified name. This is a handy way to perform an include_once operation to include a .class.php file. If the file is not found, false is returned and a warning is logged. This only includes the class: it does not instantiate an instance of it.
Note: loadClass() is deprecated since xPDO 3.0. Use Composer autoloading or addPackage() with PSR-4 instead.
Syntax¶
string|boolean loadClass (string $fqn, [ $path = ''], [ $ignorePkg = false], [ $transient = false])
The $fqn (fully qualified name) should in the format:
dir_a.dir_b.dir_c.classname
which will translate to:
XPDO_CORE_PATH/Om/dir_a/dir_b/dir_c/classname.class.php
Hint¶
- The file name you are including must include .class.php as its extension (legacy 2.x format).
- The path to your model must end in a trailing slash!
Example¶
Load a class from the path ‘/my/path/to/model/’.
$xpdo->loadClass('myBox','/my/path/to/model/');
Another example:
if (!$xpdo->loadClass('myBox','/my/path/to/model/',true,true)) {
die('Could not load class myBox!');
}
$Box = new myBox();
See Also¶
- xPDO
- modX.getService - this will include a class and instantiate it.
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
$185 per month—let's make that $500!
Learn more










