2

I am using an external to joomla script and I need to get a module's parameters.

In joomla 2.5, the code was working fine, but in j3 I have problems.

the code is:

define( '_JEXEC', 1 );
define('JPATH_BASE', getcwd().'/../../');
require_once ( JPATH_BASE.'includes/defines.php' );
require_once ( JPATH_BASE.'includes/framework.php' );

/* Create the Application */
$app = JFactory::getApplication('site');


jimport( 'joomla.application.module.helper' );
$module = &JModuleHelper::getModule( 'mod_mailformmodule');
var_dump($module);

And I get:

object(stdClass)#43 (8) {
  ["id"]=>
  int(0)
  ["title"]=>
  string(0) ""
  ["module"]=>
  string(18) "mod_mailformmodule"
  ["position"]=>
  string(0) ""
  ["content"]=>
  string(0) ""
  ["showtitle"]=>
  int(0)
  ["control"]=>
  string(0) ""
  ["params"]=>
  string(0) ""
}

If anyone has an ide why the "params" field is an empty string, I would be gratefull.

Thank you.

migrated from stackoverflow.com Sep 22 '14 at 11:00

This question came from our site for professional and enthusiast programmers.

1

It is most likely that you module does not meet the required criteria. Make sure:

  1. It is enabled.
  2. It is assigned to the current menu item or is assigned to all menu items.
  3. The user meets the access level requirements.

I have just tested the following:

define( '_JEXEC', 1 );
define('JPATH_BASE', getcwd().'/../../');
require_once ( JPATH_BASE.'includes/defines.php' );
require_once ( JPATH_BASE.'includes/framework.php' );

/* Create the Application */
$app = JFactory::getApplication('site');

jimport( 'joomla.application.module.helper' );
$module = JModuleHelper::getModule( 'mod_login' );

$registry = new JRegistry();
$params = $registry->loadString($module->params);

print_r($params);

Which is an external script importing the Joomla 3.x library, and getting the login module object. Everything works perfectly fine.

  • In my case it was that it was not enabled on the menu item (the current page). Which does raise the question - can you get a modules parameters when it is not assigned to the current menu item ? – jowan sebastian Feb 16 '17 at 17:13
  • @jowansebastian - You can't using JModuleHelper::getModule. It must meet the criteria as stated in the documentation: docs.joomla.org/JModuleHelper/getModule – Lodder Feb 16 '17 at 17:30
  • thanks. I do consider this is strange limitation though and am now using SQL to dig the data out of the DB for the module. – jowan sebastian Feb 17 '17 at 11:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy