C
C
criminalist2019-08-25 04:06:20
MODX
criminalist, 2019-08-25 04:06:20

How to get page id and store value in TV field in modx processor?

Hello, I'm asking a question here, on modx.pro I can neither log in with a login, nor with a social network, no matter how much I tried.
The question is, there is a fileattach plugin that allows you to attach files and download them, and also keeps download statistics. But, he keeps statistics for each file separately, I also need a general download stat, files are sometimes deleted and their statistics, of course, too.
I tried to get the page id to start in the file: https://github.com/13hakta/FileAttach/blob/master/...
So, at 130, the value is saved to the database +1 if the file was downloaded.
I tried to get the page id a little like this:
$c = $this->modx->getObject('modResource', $this->modx->resource->id);
the output, of course, is empty, I rarely do engine modifications, so I ask you to be indulgent.
How to get the page id from the current file and, if possible, save it in the TV field.
I read the documentation, in theory everything should work, but apparently I'm missing some details.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2019-08-27
@i__dmitry

If conditional, then it should be something like this:

$counter = 0; // Счётчик скачиваний
$id = $modx->resource->get('id'); // Получили ID текущей страницы
$res = $modx->getObject('modResource', $id); // Получили объект страницы
$res->setTVValue('tv_name', $counter + 1); // Записали значение счетчик + 1 в TV "tv_name"
$res->save(); // Сохранили ресурс

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question