php - Joomla 3! Module Parameters

457

I have a Joomla website where I have a custom module with mod_myModuleName.php and mod_myModuleName.xml files and a folder where there are several PHP scripts that add special functionality to my module. There is a config.php file in the folder that holds an associative array with variables and their values hard-coded. The module works just fine.

What I want though is to provide administrator area for the values of the variables in the array, so that I can put values in administrator panel and get their values in config.php. In my mod_myModuleName.php I use<?php echo $params->get('param')?> and it works like a charm.

But when I try to use the same technique in the config.php it breaks my code. I tried to get the values in mod_myModuleName.php and then include it in config.php and use the variables but it does not work either. I have not got so much experience in php and cannot understand what can be the reason.

It sometimes gives me an error of something non object and I guess it must be something connected with object oriented php, am I right? And if so is there a way to overcome this without object orientation or how can I solve my problem?

657

Answer

Solution:

The problem will be with the way you're using yourconfig.php.

When your modules entry point filemod_myModuleName.php is loaded by Joomla the$params object is already available in that context, you need to provide it to your scripts.

If you look at something like themod_articles_latest module you will notice that the helper class is included with this line:

require_once __DIR__ . '/helper.php';

And then helper class is has it'sgetList() method called statically with the$params passed into it, so that$params is available to class context:

$list = ModArticlesLatestHelper::getList($params);

Inside the helper classModArticlesLatestHelper you will notice that thegetList() expects the$params to be passed in.

public static function getList(&$params)
{
...
}

I would strongly recommend reading the articles in the Modules section of Developers Portal on the Joomla Doc's.

Try the "Creating a simple module" article.

People are also looking for solutions to the problem: regex - Mod Rewrite load index.php on bad path

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.