XMF Cookbook
Search…
Introducing Module Helpers
The module helper is an easy way to access module related information, such as configurations, handlers and more. Using the module helper can simplify your code.

Simplify Reading Module Configs

Consider the common task of getting a configuration value for a module. This can get more complicated if you need this in a circumstance where your module is not the currently active module.
Here is an example of how this is done now. We have a module named “bar” and we want to get the configuration “foo”:
1
$module_handler = xoops_gethandler('module');
2
$module = $module_handler->getByDirname('bar');
3
$config_handler = xoops_gethandler('config');
4
$moduleConfig = $config_handler->getConfigsByCat(0, $module->getVar('mid'));
5
$value = (isset($moduleConfig['foo']) ? $moduleConfig['foo'] : 'baz';
6
echo "The value of 'foo' being used is: " . $value;
Copied!
Here is an XMF version that accomplishes the same thing:
1
$helper = \Xmf\Module\Helper::getHelper('bar');
2
echo "The value of 'foo' being used is: " . $helper->getConfig('foo', 'baz');
Copied!

Easy Access to Module Object

Here, we extend the last example to get the module's version using our XMF module helper.
1
$version = $helper->getModule()->getVar('version');
Copied!
See the reference section for Xmf\Module\Helper for more about the module helper.
Last modified 3yr ago