TransWikia.com

Getting module parameters in AJAX call using module id

Joomla Asked by user1616338 on September 5, 2021

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;

}

One Answer

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

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

Correct answer by Sharky on September 5, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP