0

As I would like to use a front-end JavaScript framework within Joomla I would like to know what's an efficient and maintainable, structured way of accessing data from core components (such as com_content) and core modules (such as mod_menu) and exposing them as JSON.

I've searched the web and found com_ajax (Joomla's AJAX interface) to expose some JSON from modules and plugins.

However, I tried that using the following GET request:

index.php?option=com_ajax&module=menu&format=json

And it responded with:

{"success":false,"message":"Method getAjax does not exist.","messages":null,"data":null}

Thus mod_menu does not itself seem to expose any data as JSON (as a built-in function). Should I then implement that getAjax method myself?

For core components such as com_content I thought of overriding either View or Controller.

Overriding a View certainly seems like a relatively easy way to expose some data as JSON and it should probably work for both mod_menu and com_content. Though a overriding a Controller would probably execute with less overhead.

Or should I just directly query the database for data within com_content and mod_menu's tables? E.g. put those database queries in a custom component?

Is there some 'Joomla approved' way (a best practice) to do this?

  • What data are you expecting/hoping to extract from those core components/modules? Yes, if you are just looking for result set data, just set up some ajax calls that return the data from specific queries. This recent post which uses best security practices with Joomla's com_ajax should inspire: joomla.stackexchange.com/a/24287/12352 – mickmackusa Apr 22 at 10:23
  • Thanks! I was hoping to extract some blog data from com_content and the menu items from mod_menu so I could use it in a frontend JavaScript framework to make a Joomla-based PWA (Progressive Web App). And then just keep using the backend for blog entry stuff and such. Though it 'feels' like I'm "working against" Joomla by doing this. – Wieger Apr 23 at 7:17
1

Only components that specifically provide a JSON response are accessible in the JSON format. Modules are not (by design) directly addressable hence you can not call them directly, therefore, no JSON format option.

You could build a plugin to gain access to the data you wanted but that would be a 100% custom built option.

  • Good on ya, Shayne. Good to see you posting. I hope we see more of you here. – mickmackusa Apr 26 at 9:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.