XMF Cookbook
  • Introduction
  • XMF Cookbook
  • Basic Ingredients
    • Namespaces
    • Autoloading
    • Debugging
    • Forward Compatibility
  • Recipes
    • Introducing Module Helpers
    • Using the Permission Helper
      • Checking Permissions
      • Managing Item Permissions
    • Using the Session Helper
    • Using JSON Web Tokens
    • Altering Database Tables
    • Migrating a Module's Database
    • Loading Initial Data
    • Module Admin Pages
      • Hide and Seek with Icons
      • Standard Admin Pages
    • Manage Metadata
    • Highlighting Content
  • Reference
    • Assert
      • Assertions
    • Database
      • Migrate
      • TableLoad
      • Tables
        • Getting Started
        • Table Operations
        • Working with Columns
        • Working with Indexes
        • Changing Table Data
        • Interacting with the Work Queue
        • Error Info and Debugging
    • Debug
    • FilterInput
    • Highlighter
    • IPAddress
    • Jwt
      • JsonWebToken
      • KeyFactory
      • TokenFactory
      • TokenReader
    • Key
      • ArrayStorage
      • Basic
      • FileStorage
      • KeyAbstract
      • StorageInterface
    • Language
    • Metagen
      • Extracting Data
      • Applying Data
    • Module
      • Admin
      • Helper
      • Helper
        • AbstractHelper
        • Cache
        • GenericHelper
        • Permission
        • Session
    • ProxyCheck
    • Random
    • Request
    • StopWords
    • Uuid
    • Yaml
  • Credits
  • License:
  • Table of Content
Powered by GitBook
On this page
  • Simplify Reading Module Configs
  • Easy Access to Module Object
  1. Recipes

Introducing Module Helpers

PreviousRecipesNextUsing the Permission Helper

Last updated 7 years ago

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”:

$module_handler = xoops_gethandler('module');
$module         = $module_handler->getByDirname('bar');
$config_handler = xoops_gethandler('config');
$moduleConfig   = $config_handler->getConfigsByCat(0, $module->getVar('mid'));
$value = (isset($moduleConfig['foo']) ? $moduleConfig['foo'] : 'baz';
echo "The value of 'foo' being used is: " . $value;

Here is an XMF version that accomplishes the same thing:

$helper = \Xmf\Module\Helper::getHelper('bar');
echo "The value of 'foo' being used is: " . $helper->getConfig('foo', 'baz');

Easy Access to Module Object

Here, we extend the last example to get the module's version using our XMF module helper.

$version = $helper->getModule()->getVar('version');

See the reference section for for more about the module helper.

Xmf\Module\Helper