Sasha
Sasha

Reputation: 8705

Get optional parameters from custom module

I am creating custom module (I am learning how to make custom modules), and at the moment I have problem how to get custom parameters. This is XML part, for defining custom parameter:

<config>
    <fields name="params">
        <fieldset name="email_settings" label="Email Setting">

            <field name="email_receiver" type="text" default=""
                label="Receiver Email" />

        </fieldset>
    </fields>
</config>

This is helper file:

class modAskUsFormHelper
{

    public static function sendEmail($data)
    {
        $mailer = JFactory::getMailer();

    }

    public static function getAjax()
    {
        $data = modAskUsFormHelper::cleanData();
        modAskUsFormHelper::sendEmail($data);
    }

    public static function cleanData()
    {
        $input = JFactory::getApplication()->input;

        $data = array(
            'name'    => $input->get('ime', '', 'string'),
            'email'   => $input->get('email', '', 'string'),
            'tema'    => $input->get('tema', '', 'string'),
            'pitanje' => $input->get('pitanje', '', 'string')
        );
        return $data;
    }

}

When I try var_dump($this->params->get('email_receiver')); I get following error:

Fatal error: Using $this when not in object context in C:\wamp\www\joomla\modules\mod_ask_us_form\helper.php on line 21

Where is the problem?

Upvotes: 0

Views: 1169

Answers (2)

R T
R T

Reputation: 4549

for component you can get config options by following the method below:

    jimport('joomla.application.component.helper');
    $isEnableMap = JComponentHelper::getParams('com_mycomponent')->get('enable_map'); 
    var_dump($isEnableMap);exit;

Upvotes: 0

Lodder
Lodder

Reputation: 19733

Calling parameters in the helper.php is a little different to what you would normally use. You would achieve it like so:

public static function getParams($instance = 'mod_your_module'){ // replace mod_your_module
      jimport('joomla.application.module.helper');
      $module = JModuleHelper::getModule($instance);
      $moduleParams = new JRegistry;
      $moduleParams->loadString($module->params);

      return $moduleParams;
}

Then to call then in another function, simply use the folowing:

$params = static::getParams($instance);
$displayName = $params->get('email_receiver');

Hope this helps

Upvotes: 2

Related Questions