3

I am using com_ajax in joomla 2.5 - https://github.com/Joomla-Ajax-Interface/component

As I have many instances(duplicate modules) of same module from where I call to com_ajax component by jQuery ajax. So is com_ajax calls to my module's helper.php file to get data for ajax call as we know. Problem is I want to access parameters of another module instance in helper.php file which is not possible by the default call $module = JModuleHelper::getModule('mod_name_here'); so I was trying to achieve this way by passing module id to helper.php file from module's jQuery ajax call -

jimport('joomla.application.module.helper');
$input  = JFactory::getApplication()->input;
$mod_id = $input->get('module_id'); //module_id passed by ajax call             
$module = null; 
$modules = JModuleHelper::_load(); 
$total = count($modules); $name="mod_name_here";

for ($i = 0; $i < $total; $i++)
{
    // Match the name of the module
    if (($modules[$i]->name == $name || $modules[$i]->module == $name)&&($modules[$i]->id==$mod_id))
    {
        $module = $modules[$i];
        break; // Found it          
    }
}               
$params1 = new JRegistry();
$params1->loadString($module->params);

so in $params1 I am getting the settings of my desired module instance.But debugger hangs on line $modules = JModuleHelper::_load(); don't know why but when I put these same codes in a module main php file for testing, things work. So why doesn't it goes further after that line? Any alternatives?

1

I am not sure I understand your issue, because you presented no error message or something. The debugger should take you inside JModuleHelper::load() as well. My guess is that you don't provide the ItemId which is used by this function, but this is a guess.

Be advised that JModuleHelper::getModule() has two parameters:

  • $name
  • $title

You should be able to narrow your search by providing the title (somehow) as well.

Hope this helps.

  • hi problem is only in helper.php file in the module, as i wrote details about where helper.php comes into action from com_ajax. so in helper.php file debugger just don't enter load method - $modules = JModuleHelper::_load(); instead it goes to finish something rest of the joomla finishing executions. – dev-m Jul 11 '14 at 19:29
1

There's no need to use JModuleHelper to retrieve module parameters in the helper class.

Every module instance is properly created and a context variable $params is assigned for paramaters usage. For instance mod_example has $params initialized, you can just call your helper class sending the whole $params, or specific variables.

For example, mod_menu works in this way, sending the layout parameter to the helper class modMenuHelper:

// no direct access
defined('_JEXEC') or die;

// Include the syndicate functions only once
require_once dirname(__FILE__).'/helper.php';

$list   = modMenuHelper::getList($params);
$app    = JFactory::getApplication();
$menu   = $app->getMenu();
$active = $menu->getActive();
$active_id = isset($active) ? $active->id : $menu->getDefault()->id;
$path   = isset($active) ? $active->tree : array();
$showAll    = $params->get('showAllChildren');
$class_sfx  = htmlspecialchars($params->get('class_sfx'));

if(count($list)) {
    require JModuleHelper::getLayoutPath('mod_menu', $params->get('layout', 'default'));
}
  • Hi i know it. But my scenario is - i have two module instances of same module in page.both send jquery ajax call(AJAX CALL) to com_ajax (look at it) and then com_ajax calls module's helper file to get & send data back to ajax calls. Now problem is both calls getting data according to one module instance params not according to params of corresponding instance of the module.which i summarized well in question and trying to achieve. – dev-m Jul 13 '14 at 17:34
  • Ok, I see. Firstly, you can't call JModuleHelper::_load. It's a protected method. You can retrieve module parameters in this way: $the_module = JModuleHelper::getModule($mod_id); $params = $the_module->params; Secondly, instead of retrieving each module parameters, the module should send the Ajax query params. If not, the Ajax plugin has to be more clever than necessary to re-instanciate the module and "know" where get the required parameters for the query. – Anibal Jul 14 '14 at 12:01
  • Yes i knew it's protected method. And getmodule call takes only module name not module id. I have only alternative always is to send module id from jquery ajax call and in helper file i retrieve module params from database according to id by writing manual db query but it consumes much time when multiple database calls for each module instance request, also it's bit hard to implement caching myself like jmodulehelper load() does. – dev-m Jul 14 '14 at 16: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.