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

I am writing a new module for Joomla! 3 and I am stumped by $params->get.

I can see the values in the database within the modules table, but the following code returns nothing for every parameter that have been set, including the default parameters of module_tag, bootstrap_size, header_tag, header_class, style.

The code is:

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

When looking at the type of the variable $param, the type is retuned as NULL.

Joomla! 3.6.2
Stable PHP 5.6.18
MySQL 5.6.31

You have to specify the module name of which you would like to retrieve the parameters. Replace 'moduleName' with the name of your module.

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

Before getting params few points to note:

a. naming conventions There are four basic files that are used in the standard pattern of module development:

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.

Check that both the mod_helloworld.php and mod_helloworld.xml names are same.

b. Your params will only show if you have saved it once.

Check this page before jumping to retrieve params https://docs.joomla.org/J3.x:Creating_a_simple_module/Developing_a_Basic_Module

There are two options

  1. When calling from inside module use this in your mod_yourmodule.php file

    $module_tag = $params->get('module_tag', 'default value');

Then you can call $module_tag directly in your tmpl->default.php file

  1. When calling from anywhere outside a module use this

    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($module->params);

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