I need to pass some variables from one PHP module
to another PHP module
within a loop and at the same time display the module multiple times as well. I use Joomla sessions
for passing variables and its giving me some trouble. Only the last value of the variable gets passed to the second module, meaning only the value attained by a variable when the loop is over
is passed to the second module even though I use sessions within the loop.
First Module
for ($i=1;$i<5;$i++)
{
$session = JFactory::getSession();
$session->set('number', $i);
// calling second module by position
$modules = JModuleHelper::getModules("second-position");
foreach($modules as $mod)
{
echo JModuleHelper::renderModule($mod, $attribs);
}
}
Second Module
$session = JFactory::getSession();
$x = $session->get('number');
echo $x;
Output, I get
4
4
4
4
Desired Output
1
2
3
4
What's wrong, and how to correct it? Thanks in advance.
$i
with$i++
, so you end up with$session->set('number', $i++);
4
4
4