?
avatar jschmi01
jschmi01
28 Feb 2015

hi,
I've run in a problem with module which is using com_ajax getting the correct params. As with ajax the helper method will be triggered async there are only two ways to get the module's params: Either via
JModuleHelper::getModule or via Database queries to #__modules. But If you have multiple instances of your module both methods are not applicable as with getModule or with db-query you will need to know the title (which you don't) to get the correct module with its params.
I've solved/circumvented this Problem by:

  1. provide an unique id into params of each instance of module (via module's xml config)
  2. in module.php pass this id via ajax-url to helper's ajax-method
  3. in helper.php use db-query vs. #_modules table to check id in params vs passed id (if equal i got correct params)

This solution would not be neccesary if Joomla would provide a means for getting the correct module if you have multiple module instances.
I think, Joomla core should provide in addition to the params the current module-id to a module.php. I know this problem is sofar only applicable to ajax. But more extensions will exploit Joomla's core ajax interface and will require a solution for this problem.

Votes

# of Users Experiencing Issue
1/1
Average Importance Score
4.00

avatar jschmi01 jschmi01 - open - 28 Feb 2015
avatar joomla-cms-bot joomla-cms-bot - change - 28 Feb 2015
Labels Added: ?
avatar zero-24 zero-24 - change - 28 Feb 2015
Category Components
avatar zero-24 zero-24 - change - 28 Feb 2015
Category Components Modules
avatar Bakual
Bakual - comment - 28 Feb 2015

My question would be why you need the module params in com_ajax. Can't you pass the needed information in the AJAX request? That's what I would do.

If you for some reason really need the module id in the module output itself, just use $module->id. The $module object is available in each module. No need to hack something together there.
You can then pass this ID in your AJAX request just fine.

avatar Fedik
Fedik - comment - 28 Feb 2015

just add one more parameter with module title to the request, eg: &title=blabla
and JModuleHelper::getModule will give you what you want:

$app = JFactory::getApplication();
$module = JModuleHelper::getModule('mod_mymodule' , $app->input->getString('title'));
var_dump($module->params);
avatar jschmi01
jschmi01 - comment - 1 Mar 2015

hi,
you cannot use $module = JModuleHelper::getModule('mod_mymodule' , $app->input->getString('title')); - I tested this:

  1. $app->input->getString('title') will return "NULL"
  2. $module = JModuleHelper::getModule('mod_mymodule") will return the first module found, if more than one module of same name is in #_modules.

Solution with $module->id does work!!! This fixes my problem Thanks a lot.

avatar jschmi01 jschmi01 - change - 1 Mar 2015
Status New Closed
Closed_Date 0000-00-00 00:00:00 2015-03-01 10:11:02
avatar jschmi01 jschmi01 - close - 1 Mar 2015
avatar jschmi01 jschmi01 - close - 1 Mar 2015
avatar Fedik
Fedik - comment - 1 Mar 2015

@jschmi01

before use $app->input->getString('title') you must add it to your request URL :smile:
index.php?option=com_ajax&module=<Module Name>&title=<Module Title>&Itemid=<Active Menu ID>&format=<Format raw or json>
do not be lazy :wink:

avatar oorzaak
oorzaak - comment - 18 Dec 2015

Hi,

I ran into the same issue. Wouldn't it be much better if we could call JModuleHelper::getModule() with the module id instead of it's title? Using an alphanumeric string is less reliable imho that passing an id. I tried to pass the title in the com_ajax request (along with option, cmd etc.) and it doesn't work, but passing an id does work. So as for now I'm passing the id and then running and extra query in order to retrieve the title again. A bit of a waste of resources.

Passing the module title in the url as suggested by Fedik also seems a bit of a detour to me.

Kind regards, Frits


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/6231.

avatar jschmi01
jschmi01 - comment - 18 Dec 2015

Am 18.12.2015 um 16:20 schrieb oorzaak:

Hi,

I ran into the same issue. Wouldn't it be much better if we could call
JModuleHelper::getModule() with the module id instead of it's title?
Using an alphanumeric string is less reliable imho that passing an id.
I tried to pass the title in the com_ajax request (along with option,
cmd etc.) and it doesn't work, but passing an id does work. So as for
now I'm passing the id and then running and extra query in order to
retrieve the title again. A bit of a waste of resources.

Passing the module title in the url as suggested by Fedik also seems a
bit of a detour to me.

Kind regards, Frits


_This comment was created with the J!Tracker Application
https://github.com/joomla/jissues at
issues.joomla.org/joomla-cms/6231
https://issues.joomla.org/tracker/joomla-cms/6231.


Reply to this email directly or view it on GitHub
#6231 (comment).

hi,

I agree to your solution - there should be a method to get module's
properties via it's id and/or title. e.g.
"JModuleHelper::getModule($title, $id)"

MfG
Joachim Schmidt

Nußbachstr. 3
35641 Schöffengrund
Tel.: 06085-971030
Mobil: 0170-5046625

Omnis enim res, quae dando non deficit, dum habetur et non datur, nondum
habetur, quomodo habenda est.
(Wenn eine Sache nicht gemindert wird, da man sie mit anderen teilt, ist ihr Besitz unrecht, solange man sie nur allein besitzt und nicht mit anderen teilt)

avatar oorzaak
oorzaak - comment - 18 Dec 2015

Hi jschmi01,

Thx for your reply. Would there be some way to reopen this issue, as it is closed now?

Frits

avatar dadeke
dadeke - comment - 26 Jul 2017

Up up!

"JModuleHelper::getModule($name, $id)"

Add a Comment

Login with GitHub to post a comment