The code below is based on a custom Gallery Class. It returns the correct rows total, but no results. Why?
[tt]
/* build query */
$c = $modx->newQuery(’Gallery’);
if (!empty($query)) {
$c->where(array(
’name:LIKE’ => ’%’.$query.’%’,
));
}
$count = $modx->getCount(’Gallery’, $c);
$c->sortby($sort,$dir);
if ($isLimit) $c->limit($limit,$start);
$galleries = $modx->getIterator(’Gallery’, $c);
/* iterate */
$list = array();
foreach ($galleries as $gallery) {
$list[] = $gallery->toArray();
}
return $this->outputArray($list, $count); [/tt]
Output:
[tt]({"total":"3","results":[]})[/tt]
Does it work if you use getCollection?
shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect |
github |
splittingred.com
What does this give you?
return print_r($list, true);
splitting red:
getCollection() returns the same thing as getIterator().. an empty array
BobRay:
getIterator() is returning an empty array so nothing to loop over.
Shaun,
Thanks for your quick reply. I correctly ran $modx->addPackage. It turns out it was because of the sort call:
[tt]$c->sortby($sort,$dir);[/tt]
..where $sort equalled a column that wasn’t in my schema.
Checking the Error log I see now it was reporting the mysql error all along. Guess I wrongly assumed sortby() would return the mysql error to the query object instead.