xPDO.getCollection
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 morexPDO::getCollection¶
Retrieves a collection of xPDO\Om\xPDOObject instances by the specified xPDO\Om\xPDOCriteria.
If none are found, returns an empty array.
Syntax¶
array getCollection (string $className, [xPDO\Om\xPDOCriteria|array|str|int $criteria = null], [bool|int $cacheFlag = true])
If you are using xPDO map and class files generated from XML schema, the classname is not the same as your table name. Check the schema XML file:
<object class="MyClassName" table="my_class_name" extends="xPDOObject">
Examples¶
Get a collection of Box objects with a width of 40.
$boxes = $xpdo->getCollection('Box',array(
'width' => 40,
));
Get Pages¶
Often getCollection is used inside MODX Snippets, so you will call it via the $modx object and you will be fetching built-in MODX object collections, such as pages.
$pages = $modx->getCollection('modResource', array('template' => 3));
Know Your Objects!
Remember that you need to call the collection by its object name. You may find it quite handy to keep open your core/model/schema/modx.mysql.schema.xml file so you can review your object names, e.g. “modResource” for pages, or “modChunk” for chunks etc.
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
$185 per month—let's make that $500!
Learn more










