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?