Jump to main content Jump to doc navigation

xPDO::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

  • modmore
  • STERC
  • Digital Penguin
  • Jens Wittmann – Gestaltung & Entwicklung
  • CrewMark
  • Fabian Christen
  • Sepia River Studios
  • Dannevang Digital
  • A. Moreno
  • Alex
  • Chris Fickling
  • Stéphane Jäggi
  • YJ
  • Murray Wood
  • JT Skaggs
  • Anton Tarasov
  • deJaya
  • Lefthandmedia
  • eydolan
  • Following Sea
  • Guido Gallenkamp
  • Raffy
  • Snow Creative
  • Nick Clark
  • Guest
  • Helen
  • krisznet
  • Yanni
  • Richard

Budget

$185 per month—let's make that $500!

Learn more