Answer the question
In order to leave comments, you need to log in
How to implement page loading ordering on MODX revo (eg via AXAJ)?
Suppose I have a website ready and it loads quickly, but I was given a task, the implementation of which will slow down its work.
For example, counting the number of resources in a directory:
This PHP SQL task will slow down the loading of the site, and it would be logical to load the count via AJAX after the loading itself, and replace the value with a gif until it loads.
How can this task be done more efficiently with MODX?
Snippet code that counts child elements:
$id=$modx->getOption('id',$scriptProperties,0);
if ($id == 0) return 'Не задан id страницы';
$depth = 10; //глубина вложенности
$arr = $modx->getChildIds($id,$depth);//получили массив ids всех потомков(и контейнеров и документов)
if (count($arr) == 0) return '0';
$c = $modx->newQuery('modResource');
$c->where(array(
'id:IN'=>$arr, //выбираем только детей
'isfolder'=>0 //отсекаем контейнеры
));
$c->limit = 0;
$docs=$modx->getCollection('modResource',$c);//получили коллекцию детей-документов
return count($docs);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question