Joomla 3 $ params-> get返回模块中的NULL值

时间:2016-08-10 01:09:04

标签: php joomla joomla3.0

我正在为Joomla写一个新模块! 3,我被$ params-> get。

难倒

我可以在modules表中看到数据库中的值,但是以下代码不会为每个已设置的参数返回任何内容,包括module_tag,bootstrap_size,header_tag,header_class,style的默认参数。

代码是:

$app = JFactory::getApplication();
$params = $app->getParams();
$param = $params->get('module_tag');

当查看变量$ param的类型时,类型被重新调整为NULL。

的Joomla! 3.6.2
稳定的PHP 5.6.18
MySQL 5.6.31

2 个答案:

答案 0 :(得分:0)

您必须指定要检索参数的模块名称。将'moduleName'替换为模块名称。

$app = JFactory::getApplication();
$params = $app->getParams('moduleName');
$param = $params->get('module_tag');

答案 1 :(得分:0)

在获得params之前需要注意几点:

一个。命名约定 模块开发的标准模式中使用了四个基本文件:

mod_helloworld.php - This file is the main entry point for the module. 
mod_helloworld.xml - This file specifies configuration parameters for the module.
helper.php - This file do the actual work in retrieving the information  (usually from the database or some other source).
tmpl/default.php - This is the module template. This file will take the data collected by mod_helloworld.php and generate the HTML to be displayed on the page.

检查mod_helloworld.php和mod_helloworld.xml名称是否相同。

湾只有你保存一次,你的参数才会显示。

在跳转检索参数https://docs.joomla.org/J3.x:Creating_a_simple_module/Developing_a_Basic_Module

之前检查此页面

有两个选项

  1. 从内部模块调用时,请在mod_yourmodule.php文件中使用它

    $ module_tag = $ params-> get('module_tag','默认值');

  2. 然后你可以直接在你的tmpl-> default.php文件中调用$ module_tag

    1. 从模块外的任何地方拨打电话时,请使用此

      jimport('joomla.application.module.helper');

      $ module = JModuleHelper :: getModule('yourmodule');

      $ moduleParams = new JRegistry($ module-> params);

      $ module_tag = $ moduleParams ['module_tag'];

      OR

      jimport( 'joomla.html.parameter');

      jimport( 'joomla.application.module.helper');

      $ module = JModuleHelper :: getModule('yourmodule');

      $ moduleParams = new JRegistry();

      $ moduleParams->使用loadString($模块 - > PARAMS);

      $ module_tag = $ moduleParams-> get('module_tag');