getParentIds

API Quick reference
Variable name: getParentIds
CMS versions: 0.9.x + Evo
Variable type: array
Object parent:

API:getParentIds

Description

Array getChildIds(mixed $id[, int $height[, array $parents]]);

Returns an array of all parent record IDs for the id passed.

  • $id - resource ID to get parents for
  • $height - argument defines the maximum number of levels to go up.
  • $parents - array ?

Usage / Examples

$parents = $modx->getParentIds(10);

will return an array of all the parents of document 10, starting at the lowest level and working upwards, using aliases as the array keys, e.g.

Array
(
[services/accident-claims] => 3
[services] => 2
)

Function Source

function getParentIds($id, $height= 10, $parents= array ()) {
$parentId= 0;
foreach ($this->documentMap as $mapEntry) {
$parentId= array_search($id, $mapEntry);
if ($parentId) {
$parentKey= array_search($parentId, $this->documentListing);
if (!$parentKey) {
$parentKey= "$parentId";
}
$parents[$parentKey]= $parentId;
break;
}
}
$height--;
if ($parentId && $height) {
$parents= $parents + $this->getParentIds($parentId, $height, $parents);
}
return $parents;
}

Suggest an edit to this page.