1
ralf57
Need some pointers on $xoopsModule and $xoopsModuleConfig
  • 2004/12/19 10:28

  • ralf57

  • Quite a regular

  • Posts: 231

  • Since: 2003/2/3 1


Hi all,
i'm trying to build my first module.
I need to understand what $xoopsModule and $xoopsModuleConfig are used for and,most important,i need to know how to use them.
I've checked both the wikis on xoops.org and dev.xoops.org but i need an easier explaination.
So far i've only able to know that these global variables contain modules config options but i wasn't able to retrieve these options to use them.
Thanks in advance for the patience,ralf.

2
Mithrandir
Re: Need some pointers on $xoopsModule and $xoopsModuleConfig

$xoopsModule is the instance of the XoopsModule class that belongs to the module you are currently in.

This means that in the forum, the $xoopsModule variable holds an instance of XoopsModule with the properties for newbb. Usually it is used to get the current module ID ($xoopsModule->getVar('mid') ) or the module's directory name ($xoopsModule->getVar('dirname') )

$xoopsModuleConfig holds the configuration options (those set in xoops_version.php) for that same module.

This means that e.g. with these lines in xoops_version.php:
$modversion['config'][1]['name'] = 'arranger_group';
$modversion['config'][1]['title'] = '_MI_KG_ARRANGER_GROUP';
$modversion['config'][1]['description'] = '_MI_KG_ARRANGER_DESC';
$modversion['config'][1]['formtype'] = 'group';
$modversion['config'][1]['valuetype'] = 'int';
one can afterwards (in that same module's pages, i.e. not directly in blocks) access the VALUE that is set in the module's preferences page with $xoopsModuleConfig['arranger_group]

3
ralf57
Re: Need some pointers on $xoopsModule and $xoopsModuleConfig
  • 2004/12/19 15:43

  • ralf57

  • Quite a regular

  • Posts: 231

  • Since: 2003/2/3 1


Thank you mith,
clear as always.
I need to retrieve the config options values from
the global variable $xoopsModuleConfig;
let's say my module is named "mymodule"
which is the correct synthax to retrieve these values?
Does this depend on the context (ex.in a function,in a .php file,etc..)?

4
Mithrandir
Re: Need some pointers on $xoopsModule and $xoopsModuleConfig

If you are in a function or class method that is only used within your own module's pages (i.e. not used in blocks) you can just use
global $xoopsModuleConfig;
$this_config_item_value = $xoopsModuleConfig['config_name_as_in_xoops_version.php'];

If the code is in your module's own pages, you don't even need the global $xoopsModuleConfig, as you are already in the global scope and $xoopsModuleConfig is already loaded with the configuration values of the current module (your 'mymodule' module)

If you need this in a block or in a function called from a block's code, you will need to make sure that the config object is the one for the current module:
function getConfigValue($config_name) {
    global 
$xoopsModule;
    if (
$xoopsModule->getVar('dirname') == 'mymodule') {
        global 
$xoopsModuleConfig;
        
$config =& $xoopsModuleConfig;
    }
    else {
        
$mod_handler =& xoops_gethandler('module');
        
$myModule =& $mod_handler->getByDirname('mymodule');
        
$config_handler =& xoops_gethandler('config');
        
$config =& $config_handler->getConfigsByCat(0, $myModule->getVar('mid'));
    }
    return 
$config[$config_name];
}

5
ralf57
Re: Need some pointers on $xoopsModule and $xoopsModuleConfig
  • 2004/12/19 21:52

  • ralf57

  • Quite a regular

  • Posts: 231

  • Since: 2003/2/3 1


Thank you mith,
i'll try this and let you know.

6
ralf57
Re: Need some pointers on $xoopsModule and $xoopsModuleConfig
  • 2004/12/19 23:05

  • ralf57

  • Quite a regular

  • Posts: 231

  • Since: 2003/2/3 1


One last thing:
can i put the value into a variable?
I tried this but i'm not sure it's the right way...
$myvar = getConfigValue($myconfig_name);

7
Dave_L
Re: Need some pointers on $xoopsModule and $xoopsModuleConfig
  • 2004/12/20 0:34

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


That's correct, provided that $myconfig_name has the correct value.

8
ralf57
Re: Need some pointers on $xoopsModule and $xoopsModuleConfig
  • 2004/12/21 13:11

  • ralf57

  • Quite a regular

  • Posts: 231

  • Since: 2003/2/3 1


It's really strange but i still wasn't able to use the module's config otions inside the module's own pages.
Need some simple example.
Let's say i have "mymodule" and i have set some config options in xoops_version.php file:
$modversion['config'][1]['name'] = 'first_otion';
$modversion['config'][2]['name'] = 'second_otion';
etc...
What is the right code/syntax to use these values inside my code?
I'd rather to have an example with the "echo" command.
Thanks again,ralf.

9
Dave_L
Re: Need some pointers on $xoopsModule and $xoopsModuleConfig
  • 2004/12/21 13:17

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


Try this first, just to make sure the data is accessible, and that it looks right:

var_dump('xoopsModuleConfig', $xoopsModuleConfig);

If you're not sure whether it "looks right", post the output here.

10
ralf57
Re: Need some pointers on $xoopsModule and $xoopsModuleConfig
  • 2004/12/21 13:26

  • ralf57

  • Quite a regular

  • Posts: 231

  • Since: 2003/2/3 1


Thank you Dave,
i've tried with this code:
<?php
include 'mainfile.php';
var_dump('xoopsModuleConfig', $xoopsModuleConfig);
?>
and i get this error:
string(17) "xoopsModuleConfig" NULL Notice [PHP]: Undefined variable: xoopsModuleConfig in .... file test.php line2
What does this mean?
I'm afraid i'm not doing things right...