简体   繁体   中英

Joomla 3! Module Parameters

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?

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

When your modules entry point file mod_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 the mod_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's getList() method called statically with the $params passed into it, so that $params is available to class context:

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

Inside the helper class ModArticlesLatestHelper you will notice that the getList() 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM