Module parameters don't work

For Joomla! 3.x Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Post Reply
AlanCast
Joomla! Apprentice
Joomla! Apprentice
Posts: 44
Joined: Sat Dec 15, 2012 12:23 pm

Module parameters don't work

Post by AlanCast » Tue Jan 15, 2019 8:52 pm

I was trying to make a module, setting parameters from the backend.

But Joomla is not documented properly, I have no idea how to access my parameters in PHP.

After searching web I tried various methods to access the parameters from my mod_ajaxbox.php:

$params seem to be empty ("").

I get null when I try to do like this:

Code: Select all

$params->get('name')
or like this:

Code: Select all

$module = JModuleHelper::getModule('mod_headlineticker');
$headLineParams = new JRegistry($module->params);
$tickercount = (int) $headLineParams['count'];
In XML, I removed

Code: Select all

<fields>
tag wrapping, as someone advised, but that didn't help:

Code: Select all

<config>
	<fieldset name="basic">
		<field
			name="modload"
			type="text"
			label="MOD_AJAXBOX_FIELD_MODULE_LABEL"
			description="MOD_AJAXBOX_FIELD_MODULE_DESC"
			default="mod_login"
		/>
		<field
			name="onready"
			type="radio"
			label="MOD_AJAXBOX_FIELD_ONREADY_LABEL"
			description="MOD_AJAXBOX_FIELD_ONREADY_DESC"
			default="1"
			filter="integer"
			class="btn-group btn-group-yesno"
			>
			<option value="1">JYES</option>
			<option value="0">JNO</option>
		</field>
	</fieldset>
</config>
It seems the Form fields in the backend don't even save new values after I change them.

It seems like nothing works...

And I can't even find particular pieces of Joomla code of this or that class, because those classes are spread in some esoteric structure of files, and GitHub search doesn't search for precise expression... :'(
Last edited by toivo on Tue Jan 15, 2019 9:19 pm, edited 1 time in total.
Reason: mod note: moved from 3.x Extensions

 
User avatar
sozzled
Joomla! Exemplar
Joomla! Exemplar
Posts: 8698
Joined: Sun Jul 05, 2009 3:30 am
Location: Canberra, Australia
Contact:

Re: Module parameters don't work

Post by sozzled » Tue Jan 15, 2019 9:10 pm

Suggest that you look at the tutorial for creating a basic module https://docs.joomla.org/J3.x:Creating_a_simple_module

The code you're trying to use effectively says, "get the value of the parameter named name" (except that (a) the parameter "name" hasn't been defined in the XML file and (b) you haven't actually assigned the parameter to anything).
https://www.kuneze.com/blog
“If you think I’m wrong then say, ‘I think you’re wrong.’ If you say ‘You’re wrong!’, how do you know?” :)

AlanCast
Joomla! Apprentice
Joomla! Apprentice
Posts: 44
Joined: Sat Dec 15, 2012 12:23 pm

Re: Module parameters don't work

Post by AlanCast » Wed Jan 16, 2019 5:15 am

sozzled wrote:
Tue Jan 15, 2019 9:10 pm
Suggest that you look at the tutorial for creating a basic module https://docs.joomla.org/J3.x:Creating_a_simple_module

The code you're trying to use effectively says, "get the value of the parameter named name" (except that (a) the parameter "name" hasn't been defined in the XML file and (b) you haven't actually assigned the parameter to anything).
Hi sozzled,
thank you for the response.

But I said: I do LIKE THAT, it's not a piece of real code.

In real code I do something meaningful:

Code: Select all

echo $params->get('modload');
which corresponds with

Code: Select all

<field name="modload"
etc. Like I said, nothing works. And, like I said, the tutorial you point at DOESN'T HAVE REAL EXAMPLES OR EXPLANATIONS on how to work with Form Fields, except of 'sql' type.

And if I do like

Code: Select all

$language = $params->get('lang', '1');
then yes, I get it = 1, but that's not reading from parameters; it's just assigning default value.

User avatar
sozzled
Joomla! Exemplar
Joomla! Exemplar
Posts: 8698
Joined: Sun Jul 05, 2009 3:30 am
Location: Canberra, Australia
Contact:

Re: Module parameters don't work

Post by sozzled » Wed Jan 16, 2019 5:33 am

Code: Select all

$language = $params->get('lang', '1');
says, in effect, "assign the value of the parameter named lang to the variable $language but, if the parameter has not yet been set by the user or if the parameter is not defined in the XML file, use the value '1' as the default". Get the idea?

So, of course, if you haven't actually set the value to anything then it will assume that you want to use the default value. What's wrong with that?
AlanCast wrote:
Wed Jan 16, 2019 5:15 am
... the tutorial you point at doesn't have real examples or explanations on how to work with Form Fields, except of 'sql' type.
There are plenty of other examples of different types of form fields. Your Joomla website has lots of modules and these modules have parameters and you can see how they're handled.

Let's go back to the beginning of this discussion. According to your XML file you have two parameters that you want to use with your module. These are:
  • modload; and
  • onready
The first of these is a text item; the second is a radio item. What do you actually want to do with these two module parameters?
https://www.kuneze.com/blog
“If you think I’m wrong then say, ‘I think you’re wrong.’ If you say ‘You’re wrong!’, how do you know?” :)

annahersh
Joomla! Guru
Joomla! Guru
Posts: 557
Joined: Wed Aug 15, 2018 8:23 pm

Re: Module parameters don't work

Post by annahersh » Wed Jan 16, 2019 6:39 am

AlanCast wrote:
Tue Jan 15, 2019 8:52 pm
I was trying to make a module, setting parameters from the backend.

But Joomla is not documented properly, I have no idea how to access my parameters in PHP.

After searching web I tried various methods to access the parameters from my mod_ajaxbox.php:

$params seem to be empty ("")
- What is the code in mod_ajaxbox.php?
- Is mod_headlineticker a different module or have you used that name in the output file?
- Does the data output in the primary file or does it require a template file?
- What is filename which outputs echo $params->get('modload');?
- Is the module installed in the database _extensions table? If not, nothing will be written to be read. If you developed the module within the modules directory, use the Discover function to find and install it.

AlanCast
Joomla! Apprentice
Joomla! Apprentice
Posts: 44
Joined: Sat Dec 15, 2012 12:23 pm

Re: Module parameters don't work

Post by AlanCast » Wed Jan 16, 2019 11:41 am

annahersh wrote:
Wed Jan 16, 2019 6:39 am
- Is the module installed in the database _extensions table? If not, nothing will be written to be read.
Yes, I see it in the #__extensions table:
enabled = 1
access = 0
...
params = {}
and so on.
sozzled wrote:
Wed Jan 16, 2019 5:33 am
The first of these is a text item; the second is a radio item. What do you actually want to do with these two module parameters?
In #__modules, after I change form fields in the admin panel, it gets `params`:

Code: Select all

{"module_tag":"div","bootstrap_size":"0","header_tag":"h3","header_class":"","style":"0"}
but no parameters from XML.

In the admin backend, in the module configuration, when I change those raido or text fields to something else and hit "Save", they don't save but flip to the default values.

So there must be some bug in database parameters handling.

Maybe that's because I use "utf8mb64" charset, but there is a component "Akeeba Admin Tools Core 5.2.1" which is said to take care of such charset.

I ran "Repair and Optimize Tables" in that component but that didn't make difference.

PS
sozzled wrote:
Wed Jan 16, 2019 5:33 am
The first of these is a text item; the second is a radio item. What do you actually want to do with these two module parameters?
In general, I want to know how to get & set them from PHP files, and to use those settings in my module logic.

smalldragoon
Joomla! Apprentice
Joomla! Apprentice
Posts: 42
Joined: Tue Aug 02, 2011 10:26 am

Re: Module parameters don't work

Post by smalldragoon » Mon Feb 24, 2020 10:03 pm

Hi AlanCast, did you finally managed to get this working ? if yes, how ?
thanks

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 12074
Joined: Thu Feb 15, 2007 5:48 am
Location: Suzhou, China

Re: Module parameters don't work

Post by toivo » Thu Feb 27, 2020 3:42 am

Start the section with module parameters in the manifest file with these lines:

Code: Select all

	<config>
		<fields name="params">
			<fieldset name="basic">
				<field 
					name="onready"
Then the following code will work:

Code: Select all

// module parameters
$onready	= $params->get('onready', false);
Toivo Talikka, Global Moderator

 

Post Reply

Return to “Joomla! 3.x Coding”