简体   繁体   English

Joomla 3! 模块参数

[英]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. 我有一个Joomla网站,其中有一个包含mod_myModuleName.php和mod_myModuleName.xml文件的自定义模块,以及一个文件夹,其中有几个PHP脚本为模块添加了特殊功能。 There is a config.php file in the folder that holds an associative array with variables and their values hard-coded. 文件夹中有一个config.php文件,其中包含一个带有变量及其值的硬编码关联数组。 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. 我想要的是为数组中变量的值提供管理员区域,以便我可以将值放在管理员面板中并在config.php中获取它们的值。 In my mod_myModuleName.php I use <?php echo $params->get('param')?> and it works like a charm. 在我的mod_myModuleName.php中,我使用<?php echo $params->get('param')?> ,它的工作原理就像一个魅力。

But when I try to use the same technique in the config.php it breaks my code. 但是,当我尝试在config.php中使用相同的技术时,它将破坏我的代码。 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. 我试图在mod_myModuleName.php中获取值,然后将其包含在config.php中并使用变量,但它也不起作用。 I have not got so much experience in php and cannot understand what can be the reason. 我在php中没有太多经验,无法理解可能是什么原因。

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? 有时它会给我一些非对象的错误,我想一定是与面向对象的php有关的东西,对吗? 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 . 问题将出在您使用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. 当Joomla加载了模块入口点文件mod_myModuleName.php在该上下文中$params对象已经可用,您需要将其提供给脚本。

If you look at something like the mod_articles_latest module you will notice that the helper class is included with this line: 如果您查看类似mod_articles_latest模块的内容,则会注意到此行包括了helper类:

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: 然后,帮助器类将其getList()方法与传递的$params一起静态调用,以便$params可用于类上下文:

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

Inside the helper class ModArticlesLatestHelper you will notice that the getList() expects the $params to be passed in. 在帮助器类ModArticlesLatestHelper您会注意到getList()期望传入$params

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

I would strongly recommend reading the articles in the Modules section of Developers Portal on the Joomla Doc's . 我强烈建议您阅读Joomla Doc上 Developers PortalModules部分中的文章。

Try the "Creating a simple module" article. 尝试“创建简单的模块”一文。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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