Hi all,
I could really do with some help here! I’ve written a brief function to return children of a particular document - it works great on a previous installation of Revo (although I’m not sure it’s the Revo version that’s at fault here), and I can’t get it to work on this new site I’m working on.
The function in question is this:
function getChildren($id, $select) {
//
global $modx;
//
// first get the right containing page
$document = $modx->getObject('modResource',array(
'id' => $id
));
// specify what to select, along with criteria
// then get the children
$criteria = $modx->newQuery('modResource');
$criteria->select($select);
$criteria->where(array(
'published' => true,
'deleted' => false
));
$criteria->sortby('menuindex','ASC');
$children = $document->getMany('Children',$criteria);
return($children);
}
And the problem seems to be the 2nd-last line, which is returning the following error:
Fatal error: Cannot use object of type modResource_mysql as array in /homepages/26/d375149467/htdocs/core/cache/includes/elements/modsnippet/6.include.cache.php on line 50
The function is called from this line:
$siblings = getChildren($parentid, array('id','pagetitle','alias'));
Here’s the rest of the snippet so you can see the context:
// the current page
//
$pageid = $modx->resource->get('id');
// the parent page id
//
$parentid = $modx->resource->get('parent');
// get siblings
//
$siblings = getChildren($parentid, array('id','pagetitle','alias'));
// get the position of this resource in the list of children
//
for ($i = 0; $i<count($siblings); $i++) {
//
if ($siblings[$i]->get('id') == $pageid) {
$current = $i;
break;
}
}
// if there are items available after this one, 'next' skips to the next one
//
if ($current<count($siblings)-1) {
$next = $current+1;
}
// otherwise it goes to the first one
else {
$next = 0;
}
// if there are projects available before this one, 'previous' skips to the previous one
if ($current>0) {
$prev = $current-1;
}
// otherwise it goes to the last one
else {
$prev = count($siblings)-1;
}
// set placeholders
//
$modx->setPlaceholder('next',$siblings[$next]->get('id'));
$modx->setPlaceholder('prev',$siblings[$prev]->get('id'));
$modx->setPlaceholder('nexttitle',$siblings[$next]->get('pagetitle'));
$modx->setPlaceholder('prevtitle',$siblings[$prev]->get('pagetitle'));
Any help much appreciated.