0

I have a custom Joomla module. In the helper.php class, I need to pass XML field data.

Here is what I have so far.

class modcatbanerHelper {

    // I need to pass here 
    public $selected_cat = $params->get('title');

    public static function moduleCats($data)
    {
       #or pass here...
    }

}
0

You can pass in your helper's methods the $params as a parameter.

public static function moduleCats($params)
{
   $title = $params->get('title');
}

Then when you call the method from your mod_module.php:

modcatbanerHelper::moduleCats($params);
0
-1

This solution helped me to pass xml field data to class in helper.php.

public static function xyz(){
    $module = JModuleHelper::getModule('mod_name');
    $params = new JRegistry();
    $params->loadString($module->params);
    $xyz = $params->get('xyz');
    return $xyz;
}
  1. mod_name -> this is the module name. Please replace this.
  2. $params->get('xyz') -> this is the parameter found in module xml field. Please replace 'xyz'.
3
  • Thank you for sharing your snippet. Ideally, all answers should include some plain English explanation of how/why it works or reference to documentation or fringe cases where the technique is not well suited. In other words, please try to avoid posting code-only answers because these miss an opportunity to educate and empower future researchers. You may edit your answer at any time.
    – mickmackusa
    Sep 21 at 1:38
  • This is not a good solution. It gets parameters of the first instance found in the database. So if you have multiple module instances, it will get the wrong parameters.
    – Sharky
    Sep 21 at 5:37
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Sep 21 at 7:59

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.