D
D
dellakeram2018-07-05 09:36:30
MODX
dellakeram, 2018-07-05 09:36:30

How to implement simple API functionality in modx?

Hello,
How to implement api in Modx revo?
You need to output the last 4 resources in the parent with TV fields and all the charms in json.
Or the output of all resources (products) with all the information (title, tv, date, etc.) from the parent into a clear json like

[
      {
         "title": "Тайтл",
         "tv_title": "Тайтл тв",
         "tv_img_1": "/image/1.jpg"
      },{
         "title": "Тайтл2",
         "tv_title": "Тайтл тв 2",
         "tv_img_1": "/image/2.jpg"
      }
]

PS: I was able to implement similarity directly from a php file with a connection to the database through this file. But it's not safe and it was a crutch.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dellakeram, 2018-07-05
@dellakeram

Created a resource called "api", json format.
I wrote the following in the content:

[
   
]

Copied the pdoResources snippet and named it "synacs_pdoResources"
Changed it
//В место этого
return $output;
//Сделал это
return json_encode($output);

Created a chunk called api_test.
The chunk contains the following: Where title is the resource title, img is the tv parameter. Here is the output:
[
"{\"title\":\"9 \u043c\u0430\u044f\",\"img\":\"s_img\/news\/bd7e7ae0d30ee44784cb19c4921bb11e.jpg\"}\n{\"title\":\"\u0421 \u0434\u043d\u0435\u043c \u0442\u0440\u0443\u0434\u0430!\",\"img\":\"s_img\/news\/036e92f60687608f5f8f76db787bc54d.jpg\"}"
]

Everything is working. But is it right? or again muddied the crutch?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question