Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Problem when updating from 3.1.27 to 3.1.28

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
skymouse
Smarty Rookie


Joined: 05 May 2012
Posts: 7

PostPosted: Thu Sep 29, 2016 11:22 pm    Post subject: Problem when updating from 3.1.27 to 3.1.28 Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Fri Sep 30, 2016 8:14 am    Post subject: Reply with quote

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
View user's profile Send private message
skymouse
Smarty Rookie


Joined: 05 May 2012
Posts: 7

PostPosted: Fri Sep 30, 2016 8:40 am    Post subject: Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Fri Sep 30, 2016 8:49 am    Post subject: Reply with quote

Now that you've mentioned it…
http://www.smarty.net/forums/viewtopic.php?p=91170#91170
So you should use http://www.smarty.net/docs/en/api.get.template.vars.tpl as documented.
Back to top
View user's profile Send private message
skymouse
Smarty Rookie


Joined: 05 May 2012
Posts: 7

PostPosted: Fri Sep 30, 2016 9:31 am    Post subject: Reply with quote

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
View user's profile Send private message
skymouse
Smarty Rookie


Joined: 05 May 2012
Posts: 7

PostPosted: Fri Sep 30, 2016 6:57 pm    Post subject: Reply with quote

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
View user's profile Send private message
skymouse
Smarty Rookie


Joined: 05 May 2012
Posts: 7

PostPosted: Sat Oct 01, 2016 1:45 pm    Post subject: Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sun Oct 02, 2016 9:42 am    Post subject: Reply with quote

Looks like an internal name. I'd put a note here if I were you, to monitor for possible internal changes.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP