Multiple Arguments to Helper File

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

Moderators: ooffick, General Support Moderators

Forum rules
Locked
cgurn
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Fri Apr 24, 2015 1:43 am

Multiple Arguments to Helper File

Post by cgurn » Fri Apr 24, 2015 3:28 pm

I know the answer is out there somewhere, but I am challenged on finding it:

How do you pass multiple arguments from a module to a helper.php file and then parse out the values for use in the helper file?

============
If you want the details, here is what is happening. I am very much old school, but making headway on figuring this out.

Currently, I have a module that sends a string to itself, looks up characters in the string in a table, and return attributes of the characters within the string.

I can do this (repeating this basic sql chain several times) in the mod_testcode.php (Only one record will be returned):

// Create a new query object.
$query = $db->getQuery(true);

// build the SQL query
$query->select('strVarString');
$query->from($db->quoteName('tjm1_testdecoder'));
$query->where($db->quoteName('strVariable') . '='.$db->quote(Series), 'AND');
$query->where($db->quoteName('strVarValue').' = '.$db->quote($series));

// Reset the query using our new query object
$db->setQuery($query);

// Load the single result
$series = $db->loadResult();
=================

I have items like Series, Market, Users, Years, etc, all using the same basic sql. I would like to send this to a helper.php, something like:

$vin_var = 'Series';
$series = modTestcodeHelper::getDecoder($item($vin_var, $series)); // this can't be right!

In the helper file:

public static function getDecoder($params)
{
$att_name = $params->get('items', 0); // this is where it implodes
$att_value = $params->get('items', 1);

I know this is not how you send multiple parameters, cause it doesn't work. But I have spent way too much time looking for a simple example, to no success. Probably just using wrong search terms.

Thanks in advance ...
Chris

cgurn
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Fri Apr 24, 2015 1:43 am

Re: Multiple Arguments to Helper File

Post by cgurn » Sat Apr 25, 2015 12:04 am

Okay.
That didn't take long. Not really a Joomla question, but a .php question. Went back to my understanding of arrays.

Passed the arguments with:

$vin_var = 'Series';
$att_id = $series;
$series = modTestcodeHelper::getDecoder(
array(
'vin_var' => $vin_var,
'att_id' => $att_id
)
);

Good use of memory, but terrible use of variables! :)

Received in the helper file:
$att_name = $params['vin_var'];
$att_value = $params['att_id'];

Works like a champ. Thanks for reading!


Locked

Return to “Joomla! 3.x Coding”