Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
incorrect result when send variables to php function

 
Post new topic   Reply to topic    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
fastdev
Smarty n00b


Joined: 19 Nov 2012
Posts: 3

PostPosted: Mon Nov 19, 2012 12:26 pm    Post subject: incorrect result when send variables to php function Reply with quote

here is smarty code:
Code:

<div class="pagination">
<a href="{$core->bulidPagination(1,0,$action,$category,$category_title,$adtype,$search_term)}">First</a><span class="disabled">.</span>
{if $pagenum>1}<a href="{$core->bulidPagination($prevpage,0,$action,$category,$category_title,$adtype,$search_term)}"><b>Prev</b></a>{else}<span class="disabled">Prev</span>{/if}
<span class="disabled">...</span>
{if $pagenum-3>0}
<a href="{$core->bulidPagination($pagenum,-3,$action,$category,$category_title,$adtype,$search_term)}">{$pagenum-3}</a>
{/if}
{if $pagenum-2>0}
<a href="{$core->bulidPagination($pagenum,-2,$action,$category,$category_title,$adtype,$search_term)}">{$pagenum-2}</a>
{/if}
{if $pagenum-1>0}
<a href="{$core->bulidPagination($pagenum,-1,$action,$category,$category_title,$adtype,$search_term)}">{$pagenum-1}</a>
{/if}
<span class="current">{$pagenum}</span>
{if $pagenum+1<=$lastpage}
<a href="{$core->bulidPagination($pagenum,1,$action,$category,$category_title,$adtype,$search_term)}">{$pagenum+1}</a>
{/if}
{if $pagenum+2<=$lastpage}
<a href="{$core->bulidPagination($pagenum,2,$action,$category,$category_title,$adtype,$search_term)}">{$pagenum+2}</a>
{/if}
{if $pagenum+3<=$lastpage}
<a href="{$core->bulidPagination($pagenum,3,$action,$category,$category_title,$adtype,$search_term)}">{$pagenum+3}</a>
{/if}
<span class="disabled">...</span>
{if $pagenum<$lastpage}<a href="{$core->bulidPagination($nextpage,0,$action,$category,$category_title,$adtype,$search_term)}"><b>Next</b></a>{else}<span class="disabled">Next</span>{/if}
<span class="disabled">.</span><a href="{$core->bulidPagination($lastpage,0,$action,$category,$category_title,$adtype,$search_term)}">Last</a>
</div>

and here is function:
Code:

class CoreClass {

function bulidPagination($pagenum, $pad, $action,$category,$category_title,$ads,$search_term) {
   
   if($action=='browse')
      return SITE_ROOT."classified-ads-".($ads=='golden'?'golden-':'').$category."_".($pagenum+$pad).($category_title!=''?"-".$category_title:'').".html".($search_term!=''?'?'.rawurlencode($search_term):'');
   else
      return
      SITE_ROOT."search?action=".$action."&amp;page=".($pagenum+$pad)."&amp;".$search_term;
   
}

}

let's show bug with example:
Code:


$core = new CoreClass();

$tpl->assign('core', $core);

$pagenum=4;
$action='browse';
$category=0;
$category_title='test';
$adtype='';
$search_term='';


$tpl->assign('pagenum', $pagenum);
$tpl->assign('action', $action);
$tpl->assign('category', $category);
$tpl->assign('adtype', $adtype);
$tpl->assign('category_title', $category_title);
$tpl->assign('search_term', $search_term);


when second parameter is minus, smarty do not send correct set of parameters to function. in this example:

<a href="{$core->bulidPagination($pagenum,-3,$action,$category,$category_title,$adtype,$search_term)}">{$pagenum-3}</a>

smarty send -3 as first parameter! and $action become next on ($category value! which is zero).. so instead geting result from first return in buildPagination function I get result from second return! (because $action become 0 and not 'browse' string).
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 4673
Location: Hamburg / Germany

PostPosted: Mon Nov 19, 2012 8:10 pm    Post subject: Reply with quote

The compiled code of Smarty is
Code:
<a href="<?php echo $_smarty_tpl->tpl_vars['core']->value->bulidPagination($_smarty_tpl->tpl_vars['pagenum']->value,-3,$_smarty_tpl->tpl_vars['action']->value,$_smarty_tpl->tpl_vars['category']->value,$_smarty_tpl->tpl_vars['category_title']->value,$_smarty_tpl->tpl_vars['adtype']->value,$_smarty_tpl->tpl_vars['search_term']->value);?>
">


As you can see the -3 is passed as 2nd parameter.

btw. which Smarty version do you use?
Back to top
View user's profile Send private message
fastdev
Smarty n00b


Joined: 19 Nov 2012
Posts: 3

PostPosted: Tue Nov 20, 2012 8:24 am    Post subject: Reply with quote

I am using 2.6.26
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 4673
Location: Hamburg / Germany

PostPosted: Wed Nov 21, 2012 9:52 pm    Post subject: Reply with quote

Indeed there is a bug in the compiler of Smarty 2.
We will try to fix this ASAP.
Back to top
View user's profile Send private message
fastdev
Smarty n00b


Joined: 19 Nov 2012
Posts: 3

PostPosted: Fri Nov 23, 2012 1:14 pm    Post subject: Reply with quote

temporary solution I used:

<a href="{$core->bulidPagination($pagenum,'-3',$action,$category,$category_title,$adtype,$search_term)}">{$pagenum-3}</a>
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Bugs 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