View previous topic :: View next topic |
Author |
Message |
skymouse Smarty Rookie
Joined: 05 May 2012 Posts: 7
|
Posted: Thu Sep 29, 2016 11:22 pm Post subject: Problem when updating from 3.1.27 to 3.1.28 |
|
|
I've got some code in a plugin that has worked forever, but upgrading from 3.1.27 to 3.1.28 breaks it. Here's the part that's affected:
Code: |
function smarty_function_myfunction($params, Smarty_Internal_Template $template) {
// . . .
$z = $template->tpl_vars['smarty']->value['section'][$i]['index'];
// . . .
}
|
I get this error in my PHP error log (line 22 being the line shown in the function above):
Code: |
Undefined index: smarty in /blahblahblah/function.myfunction.php on line 22
|
Reverting to 3.1.27 (and earlier) makes it work again.[/code] |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Sep 30, 2016 8:14 am Post subject: |
|
|
Why you are "upgrading" to 3.1.28 when the latest release is 3.1.30 ?
Also, shouldn't that be
Code: | $z = $template->tpl_vars['section'][$i]['index']; |
? |
|
Back to top |
|
skymouse Smarty Rookie
Joined: 05 May 2012 Posts: 7
|
Posted: Fri Sep 30, 2016 8:40 am Post subject: |
|
|
Many thanks for replying.
Quote: |
Also, shouldn't that be
Code: | $z = $template->tpl_vars['section'][$i]['index']; |
? |
I don't know. I've had my version for ages and it has always worked. Maybe my way only worked accidentally. I will try your code and see what happens.
AnrDaemon wrote: | Why you are "upgrading" to 3.1.28 when the latest release is 3.1.30 ? |
I tried 1.3.30 first of all as it's the latest version. I got some errors at that point, and so tried changing to an earlier version to see at which version the error first starts. This is how I arrived at 3.1.28, as that provokes the issue and 3.127 doesn't. Once I've resolved it I'll try 3.1.30 again. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
|
Back to top |
|
skymouse Smarty Rookie
Joined: 05 May 2012 Posts: 7
|
Posted: Fri Sep 30, 2016 9:31 am Post subject: |
|
|
Still using 3.1.27, I tried
Code: |
$z = $template->getTemplateVars('section')[$i]['index'];
|
and that gave me
Undefined index: in /usr/www/virtual/philphuk/smarty/smplugins/function.modelpic.php on line 48
I get the same "blank" undefined index error when I also try the following:
Code: |
$z = $template->tpl_vars['section'][$i]['index'];
|
and
Code: |
global $smarty; // defined globally in main PHP program
$z = $smarty->getTemplateVars('section')[$i]['index'];
|
|
|
Back to top |
|
skymouse Smarty Rookie
Joined: 05 May 2012 Posts: 7
|
Posted: Fri Sep 30, 2016 6:57 pm Post subject: |
|
|
Ok, I'm making progress. This syntax works (at least in 3.1.27 ... I'm going to retry the upgrade shortly):
Code: |
$z = $template->getTemplateVars('smarty')['section'][$i]['index'];
|
|
|
Back to top |
|
skymouse Smarty Rookie
Joined: 05 May 2012 Posts: 7
|
Posted: Sat Oct 01, 2016 1:45 pm Post subject: |
|
|
Right, I've solved the mystery.
Code: |
# Programmatically get the current index of a
# 3.1.27 version -- no longer works beyond v3.1.27
$idx = $template->getTemplateVars('smarty')['section'][$sectionName]['index'];
# 3.1.30 version
$idx = $template->getTemplateVars("__smarty_section_$sectionName")['index'];
|
Anr, many thanks for your tip about using getTemplateVar: I'm now doing that. Fixing that, as well as changing the indexes as above to relect the fact that Smarty changed the structure of the values returned vy getTemplateVars(), have together solved the problem. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sun Oct 02, 2016 9:42 am Post subject: |
|
|
Looks like an internal name. I'd put a note here if I were you, to monitor for possible internal changes. |
|
Back to top |
|
|