Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

[Paginate]: SmartyPaginate::getCurrentIndex() returns -1

 
Post new topic   Reply to topic    Smarty Forum Index -> Add-ons
View previous topic :: View next topic  
Author Message
HEMOglobina
Smarty Rookie


Joined: 30 Aug 2005
Posts: 11

PostPosted: Tue Sep 13, 2005 1:07 am    Post subject: [Paginate]: SmartyPaginate::getCurrentIndex() returns -1 Reply with quote

This is my first time using smartyPaginate and I'm having some trouble because it is returning -1 when I call SmartyPaginate::getCurrentIndex().
This is a snippet from my query:
Code:

SmartyPaginate::connect();
SmartyPaginate::setLimit(25);
$qry_rsTop = sprintf("SELECT SQL_CALC_FOUND_ROWS * FROM xpto_topicos ORDER BY topic_time LIMIT %d,%d", SmartyPaginate::getCurrentIndex(), SmartyPaginate::getLimit() );


As far as I know, LIMIT cannot be like LIMIT -1,20. Am I supposed to check for it before using?

Thanks in advance,
HEMOglobina
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7365
Location: Lincoln Nebraska, USA

PostPosted: Tue Sep 13, 2005 2:05 pm    Post subject: Reply with quote

I'm not sure why that is happening. Do you have PHP sessions enabled?

When you call

[php:1:46ebdcebee]SmartyPaginate::connect();[/php:1:46ebdcebee]

That should initialize everything. Then when you call:

[php:1:46ebdcebee]SmartyPaginate::getCurrentIndex();[/php:1:46ebdcebee]

You should get a value of 0 to start with, not -1.
Back to top
View user's profile Send private message Visit poster's website
HEMOglobina
Smarty Rookie


Joined: 30 Aug 2005
Posts: 11

PostPosted: Tue Sep 13, 2005 4:43 pm    Post subject: Reply with quote

Hello mohrt.
Yes, I have sessions enabled. Taken from my phpinfo(): "Session Support enabled"

I also noticed that after I call SmartyPaginate::reset(), everything works correctly. I mean, if I do this way:
Code:

SmartyPaginate::connect();
SmartyPaginate::reset(); // NOTE THIS
SmartyPaginate::setLimit(5);
   
$top_array = $this->getFromDB();

$this->tpl->assign('topics', $top_array);
SmartyPaginate::assign($this->tpl);      
$this->tpl->display('pub_home.tpl');

I dont get the SQL error, but i since I'm resetting, paginate doesnt work as expected.

At this time I solved the problem with an if statment, where I check if SmartyPaginate::getCurrentIndex() returns -1. If it does, I force the SQL limit to 0. This only happens once before the first call to SmartyPaginate::reset(). So, in the end my code is like the following:
Code:

SmartyPaginate::connect();
SmartyPaginate::setLimit(5);
   
$top_array = $this->getFromDB();

$this->tpl->assign('topics', $top_array);
SmartyPaginate::assign($this->tpl);      
$this->tpl->display('pub_home.tpl');
SmartyPaginate::reset(); // CORRECT PLACE


And inside the getFromDB function, I check to see if getCurrentIndex is returning -1 or not.

Is this a bug? If you need, I could send you the output of my phpinfo().

Thank you very much,
HEMOglobina

[edit]I forgot to mention that if I dont call SmartyPaginate::reset(), SmartyPaginate doesnt work at all... I shows the pages links, but if I click them nothing happens[/edit]
Back to top
View user's profile Send private message
jozwikjp
Smarty Rookie


Joined: 04 Aug 2006
Posts: 9

PostPosted: Fri Oct 09, 2009 7:31 pm    Post subject: Reply with quote

I have also had this same issue.

I added this after smarty is initialized.

Code:
  if(SmartyPaginate::getCurrentIndex()=='-1'){SmartyPaginate::reset(); }   


Seems to have fixed that issue.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Add-ons 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