1
Mazarin
Accessing xoopsModuleConfig from a block
  • 2009/10/11 20:17

  • Mazarin

  • Just can't stay away

  • Posts: 533

  • Since: 2008/12/10


I use 2.3.2 and am trying to access xoopsModuleConfig from a block to get some preferences for a module. Unfortunately it doesn't seem to work as I don't get any values, so I'm wondering if there are any obvious things when calling xoopsModuleConfig that I'm missing here?

I'm calling them through a static function in a module and the function works and gets called. I've checked the db and the values are there. It works perfectly fine when I try to access them through the actual module, but not from the block.

I know I could just make my own call to the db, but I might as well use what's built into XOOPS if possible.

2
ghia
Re: Accessing xoopsModuleConfig from a block
  • 2009/10/11 20:55

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


Error messages in debug?

3
Mazarin
Re: Accessing xoopsModuleConfig from a block
  • 2009/10/12 6:28

  • Mazarin

  • Just can't stay away

  • Posts: 533

  • Since: 2008/12/10


Just this warning:
Warning: xoopsOption[template_main] should be defined before including header.php in file /footer.php line 68

I haven't done anything to those files, so I assume this has nothing to do with my problem?

4
stefan88
Re: Accessing xoopsModuleConfig from a block
  • 2009/10/12 21:06

  • stefan88

  • Community Support Member

  • Posts: 1086

  • Since: 2004/9/20


Hi,

this works in 2.0.13.2:

$module_handler =& xoops_gethandler('module');
  
$module =& $module_handler->getByDirname($mydirname);
  
$config_handler =& xoops_gethandler('config');
  
$moduleConfig =& $config_handler->getConfigsByCat(0$module->getVar('mid'));



and then $moduleConfig['option_name'] where option_name is the property you want to access.

Hope this is some help :)

5
Mazarin
Re: Accessing xoopsModuleConfig from a block
  • 2009/10/14 19:02

  • Mazarin

  • Just can't stay away

  • Posts: 533

  • Since: 2008/12/10


Thx for the help, but unfortunately it didn't work.

The key here is why it works from within the module and when the block is displayed together with the module, but not when the block is displayed together with other modules.

(The module is XoopsPoll and the parameter I'm trying to get is limit_by_id and limit_by_ip)

6
frankblack
Re: Accessing xoopsModuleConfig from a block
  • 2009/10/14 19:12

  • frankblack

  • Just can't stay away

  • Posts: 830

  • Since: 2005/6/13


Just to be sure
$module =& $module_handler->getByDirname($mydirname);


In your case $mydirname should be 'xoopspoll'. The above mentioned code has to work, I use it myself.

7
Mazarin
Re: Accessing xoopsModuleConfig from a block
  • 2009/10/14 19:57

  • Mazarin

  • Just can't stay away

  • Posts: 533

  • Since: 2008/12/10


But it doesn't. I'm sure that there is some fundamental mistake I'm doing or some concept I haven't grasped.

I'm calling a static function in a class (in a separate file) from the block show function. The static function called then declares global $xoopsModuleConfig and uses that to get the $xoopsModuleConfig['limit_by_uid'] .

Now, why does it work when showing the block together with the module, but not when showing it together with other modules? To me it seems like it is dependent on something being initiated (or to that effect), which it isn't when calling just the static function.

Is it so that you can only call parameters using the global $xoopsModuleConfig from the "active" module? (makes sense now that I think about it)

Is this what your code above is trying to circumvent (though it doesn't work for me)?

8
frankblack
Re: Accessing xoopsModuleConfig from a block
  • 2009/10/14 21:04

  • frankblack

  • Just can't stay away

  • Posts: 830

  • Since: 2005/6/13


post your block code and we will see. to access the config array inside the block it must be $moduleConfig['limit_by_uid']

9
Mazarin
Re: Accessing xoopsModuleConfig from a block
  • 2009/10/14 21:15

  • Mazarin

  • Just can't stay away

  • Posts: 533

  • Since: 2008/12/10


Let's take a step back and answer some fundamentals first:
The way you describe it, can you call module parameters without having it as the "active" module, i.e. from a block or a different module?

I don't think there's anything wrong with the code per se. I have changed very little and it does work with the xoopspoll module.

Regarding the code posted in this thread, I get an error for a function call on a non-object (the getVar).

10
ghia
Re: Accessing xoopsModuleConfig from a block
  • 2009/10/15 1:00

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


Not sure xoopspoll has a module handler. Maybe look up the id of the module and specify it in $mid directly
$config_handler =& xoops_gethandler('config');
  
$moduleConfig =& $config_handler->getConfigsByCat(0$mid);

Login

Who's Online

393 user(s) are online (279 user(s) are browsing Support Forums)


Members: 0


Guests: 393


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits