1

I have set up an AJAX call in my module which works fine. I want to get the module parameters when I make the ajax call. So I'm doing this

$app = JFactory::getApplication();
$module = JModuleHelper::getModule('mod_moduleName_display');
$params = new JRegistry($module->params);

This works fine except I have multiple mod_moduleName_display modules instances. So it picks up the first module parameters not the one I want.

I can't find a way to get the module parameters using the module id. I could pass them into the AJAX call or get them directly from the modules table but I'm hoping that there is a standard Joomla way of doing this that I've missed.

Update showing code for AJAX call:

sermon contains the module id - i.e. sermons.moduleToUse

function runAjax(page){

    page_no = page;
    moduleToUSe =  sermons.moduleToUse;
    sermons.start = page;
    var dataJSON = sermons;

    request = {
        'option' : 'com_ajax',
        'module' :  moduleToUSe,
        'parameters'  :  sermons,
        'format' : 'json'
    };

    jQuery.ajax({
        type   : 'POST',
        data   : request,
        success: function (jsonObj) {
            jQuery("#container").html("");

            jsonArrayResponse =  jQuery.parseJSON(jsonObj["data"]);

            console.log(jsonArrayResponse);

        }
    });

    return false;

}
  • Can you show us the Ajax call? You want to get the modules parameters, right? – Thiago Guimarães Jul 5 at 15:19
  • 1
    I've added the Ajax call. I pass an object with the module id which I want to use in the AJAX code to get the module params. I can do this with a database call to the modules table but I hoped Joomla had a class so that the code would be more future proofed against changes – user1616338 Jul 5 at 15:27
  • I have a solution but I'm not sure if this is what you need. – Thiago Guimarães Jul 5 at 15:28
2

If you know the ID, you can use JModuleHelper::getModuleById().

https://api.joomla.org/cms-3/classes/Joomla.CMS.Helper.ModuleHelper.html#method_getModuleById

| improve this answer | |
  • 1
    Thanks this is just what I wanted. I'd already written code to get it from the _modules table but I really wanted to use the official joomla method. – user1616338 Jul 5 at 15:51

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.