A
A
ADMIN INDIGO2019-09-30 10:49:53
MODX
ADMIN INDIGO, 2019-09-30 10:49:53

How to get migx data array?

How do I get an array of data from migx so that I can use it in a snippet. I need to make conditions there and it is very easy to work on php. But I don’t understand how to get an array, I understand that I need to give the correct query to the database, but I don’t know how. Is there anyone knows?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2019-09-30
@INDIGO1

If we are talking about data that is saved in TV with the migx input field, then the output is JSON.
That is, the work will be something like this:

$doc = $modx->getObject('modResource', 15); // Получили объект ресурса с ID, например, 15
$migx_value =  json_decode($doc->getTVValue('your_tv'), true); // получили значение TV и перекодировали из JSON в массив

And then went any work.
In templates, it is convenient to work with such values ​​through Fenom:
{set $val = $_modx->resource.my_tv | json_decode : true}
// Любые операции, например, перебор
{foreach $val as $item}
<p>{$item.title}</p>
{/foreach}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question