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

SmartyPaginate 1.6 released
Goto page Previous  1, 2, 3, 4  Next
 
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 -> Add-ons
View previous topic :: View next topic  
Author Message
equak
Smarty n00b


Joined: 17 Mar 2008
Posts: 2

PostPosted: Mon Mar 17, 2008 4:24 am    Post subject: Bug report and fixed Reply with quote

I have found a bug while testing hardly this pagination plugin into my project. Here is how i describe it.

Bug description:
When a page limit is set and the last page contains 1 item only, the last page is not shown in the pagination groups.

Here are the script parts to reproduce the bug (the code in bold is the code i added/modified to force the bug to occur):

Quote:
index.php
---------
<?php
session_start();
require('Smarty.class.php');
require('SmartyPaginate.class.php');

$smarty =& new Smarty;

// required connect
SmartyPaginate::connect();
SmartyPaginate::setPageLimit(5);
// set items per page
SmartyPaginate::setLimit(25);

// assign your db results to the template
$smarty->assign('results', get_db_results());
// assign {$paginate} var
SmartyPaginate::assign($smarty);
// display results
$smarty->display('index.tpl');

function get_db_results() {
// normally you would have an SQL query here,
// for this example we fabricate a 100 item array
// (emulating a table with 100 records)
// and slice out our pagination range
// (emulating a LIMIT X,Y MySQL clause)
// i forced it to have 5 page of 25 items + 1 page with 1 item = 6 pages total (considering we set the page limit to 5 up there and the limit to 25)
$_data = range(1,126);

SmartyPaginate::setTotal(count($_data));
return array_slice($_data, SmartyPaginate::getCurrentIndex(),
SmartyPaginate::getLimit());
}
?>


Quote:
index.tpl
---------
{* display pagination header *}
Items {$paginate.first}-{$paginate.last} out of {$paginate.total} displayed.
<br />
{* display results *}
{section name=res loop=$results}
{$results[res]}
{/section}
<br />
{* display pagination info (format="page" for better bug visualization) *}
{paginate_prev} {paginate_middle format="page"} {paginate_next}


Here is the result when we navigate through the 6 pages:

Quote:


Bug fix description:

File: SMARTY_DIR/plugin/function.paginate_middle.php
Line: 108
Fix: math calculation causing the problem. Add "- $_limit" at the end of the line.

Here is a screenshot of the fix. The fix is in bold:

Quote:
if(isset($_page_limit)) {
// find halfway point
$_page_limit_half = floor($_page_limit / 2);
// determine what item/page we start with
$_item_start = $_curr_item - $_limit * $_page_limit_half;
if( ($_view = ceil(($_total - $_item_start) / $_limit)) < $_page_limit) {
$_item_start -= ($_limit * ( $_page_limit - $_view )) - $_limit;
}
$_item = ($_item_start >= 1) ? $_item_start : 1;
$_page = ceil($_item / $_limit);
}


Here is the result when we navigate through the 6 pages with the fix applied:

Quote:


Hope you add it to the CVS asap.
Enjoy!
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Sat Apr 05, 2008 1:28 am    Post subject: Reply with quote

added to CVS, thanks!
Back to top
View user's profile Send private message Visit poster's website
gtraxx
Smarty Regular


Joined: 08 Jan 2008
Posts: 56

PostPosted: Tue May 06, 2008 10:31 am    Post subject: Reply with quote

Hello, do we know use mysql driver PDO has the place of traditional functions of connection to database?
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Tue May 06, 2008 1:51 pm    Post subject: Reply with quote

Use whatever you want to connect to the database, SmartyPaginate doesn't care.
Back to top
View user's profile Send private message Visit poster's website
gflou
Smarty n00b


Joined: 11 May 2008
Posts: 1

PostPosted: Sun May 11, 2008 3:22 pm    Post subject: portion of data to be paginated Reply with quote

Hey Monte,

I am working on a project where I receive data concerning availability information for a hotel in json format from an external site (I do not have control over the sql queries) and after I decode them I assign the whole data to a template variable. As I understand the $pagination variable is populated with SmartyPaginate::assign($smarty) but in my case the $smarty object contains many more data than only those who needs to be paginated. In particular the array to be paginated is an attribute of one of the objects that constitute the whole data returned.

The only way to populate the $paginate variable with only the portion of data I need is with the SmartyPaginate::assign($smarty, 'data_to_paginate', 'pageID') or there is another way?
Back to top
View user's profile Send private message
anorgan
Smarty n00b


Joined: 18 Oct 2008
Posts: 4

PostPosted: Sat Oct 18, 2008 11:53 pm    Post subject: Reply with quote

good plugin, altough i use paginateit class
Back to top
View user's profile Send private message
manfred
Smarty Rookie


Joined: 07 Oct 2008
Posts: 10

PostPosted: Mon Nov 17, 2008 8:26 pm    Post subject: Reply with quote

hello can you help me to retrieve data from mysql db one example?

Code:

function get_db_results() {
       
$_data = range(1,100);
SmartyPaginate::setTotal(count($_data));
return array_slice($_data, SmartyPaginate::getCurrentIndex(),
SmartyPaginate::getLimit());
    }

how i put query in hte function


my query = mysql_query("SELECT * FROM users");
also needed to print the result (username) in template.
thanks
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Mon Nov 17, 2008 8:35 pm    Post subject: Reply with quote

There is a mysql example in the SmartyPaginate documentation, further down the page. Please read through the whole docs.
Back to top
View user's profile Send private message Visit poster's website
NiCkYsTyLe
Smarty n00b


Joined: 16 Jan 2009
Posts: 1

PostPosted: Fri Jan 16, 2009 9:28 pm    Post subject: Reply with quote

Hi here !

I'm pretty new to PHP and Smarty, but i've made Smarty work in my own written website, now i was working on a nice error handler today and everything works fine, untill... i've visit a page where i use SmartyPaginate. I've got lots and lots of errors, mayB you can help me out with it? Because i realy like this plugin and i want to use it, but with so much errors i can;t work with it.

An example error, most of the errors looks like this:
Code:

PHP_version: PHP Version 5.2.6
Error_date: 01-16-2009 22:24:48 +0100
Error_type: Unknown
Error_file: D:\Programma's\xampp\htdocs\nick\V2\admin\Sections\manager\news.php
Error_line: 108
Error_msg: Non-static method SmartyPaginate::connect() should not be called statically
Client_ip: 127.0.0.1
Client_uri: /nick/v2/admin/index.php?section=manager&action=news
Client_user-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; nl; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5
Server_host: localhost
Client_referer: http://localhost/nick/v2/admin/index.php?section=manager
Error_simpel: Runtime Notice: Non-static method SmartyPaginate::connect() should not be called statically In D:\Programma's\xampp\htdocs\nick\V2\admin\Sections\manager\news.php On line 108

Script, line: 108


104    {
105        session_start();
106           
107       // required connect
108        SmartyPaginate::connect();
109        // set items per page
110       SmartyPaginate::setLimit(21);
111
112       
113       SmartyPaginate::setUrl('index.php?section=manager&action=news');
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Sat Jan 17, 2009 12:34 am    Post subject: Reply with quote

PHP5 complains about that. Just add "static" in front of the methods that are called statically, as PHP5 would like them. At some point we'll probably drop PHP4 support.

Code:
class SmartyPaginate {
    public static function connect() {
        // ...
    }
}


http://us.php.net/manual/en/language.oop5.static.php
Back to top
View user's profile Send private message Visit poster's website
sangprabv
Smarty Rookie


Joined: 14 Feb 2005
Posts: 13
Location: Jakarta

PostPosted: Fri Jan 30, 2009 9:26 am    Post subject: Integrate Paginate With Form Result and ResetSession Problem Reply with quote

When I have a form and do a query which return results in 2 pages, I found problem on how to carry the query result in to the 2nd page and also back to 1st page as well.
Also when I use paginate in 2 separete php file, a.php and b.php, why when I move next in a.php?step=20 will cause link (a href) in b.php to read a.php?step=20?
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
netnerd85
Smarty n00b


Joined: 23 Feb 2009
Posts: 1

PostPosted: Mon Feb 23, 2009 2:14 pm    Post subject: Reply with quote

For those that might have some trouble here is what I did to get it working:

Code:

//get all count
$total = count($db->get_all());
   
SmartyPaginate::connect();
//set the max per page
SmartyPaginate::setlimit('5');

//set the offset and limit
$db->to = SmartyPaginate::getCurrentIndex();
$db->from = SmartyPaginate::getlimit();

//get the limited set
$all_records = $db->get_all();

SmartyPaginate::setTotal($total);
SmartyPaginate::assign($smarty);
Back to top
View user's profile Send private message
Michael Dyrynda
Smarty n00b


Joined: 20 May 2009
Posts: 1

PostPosted: Wed May 20, 2009 7:33 am    Post subject: Re: {$paginate.current_item} - not for multiple pagination s Reply with quote

tdmf wrote:
As it appears, {$paginate.current_item} will ONLY output the correct value in the "default" instance and theres no support for {$paginate.current_item id="mydata"}, right ?


I know it's a bit late but I thought I'd post my solution for others as it'll probably come up again. After some tinkering and looking at the code, it dawned on me that the {paginate_first id='mydata'} is a smarty function, not a variable as with {$paginate.first}.

For this to work, your $paginate->assign() call must be correct.

Rather than just:

Code:

$paginate->assign($smarty)


You'll need to do something like:

Code:

$paginate->assign($smarty, 'paginate', 'mydata');


Essentially, you have to pass the correct var name (paginate) to smarty, along with the correct id (mydata).

Hope this helps.

- Dy

p.s. You'll note I reference assign as part of the $paginate method, rather than statically (SmartyPaginate::assign) due to PHP5 compatibility issues (as noted elsewhere here).

Code:

// Essentially, PHP5 complains about calling non-static methods statically
// We instead instantiate the class
$paginate = new SmartyPaginate();

// Rather than calling
SmartyPaginate::connect('mydata');

// We call
$paginate->connect('mydata');

// and so on
Back to top
View user's profile Send private message
stot
Smarty Rookie


Joined: 13 Nov 2006
Posts: 17

PostPosted: Sun Jun 21, 2009 4:54 pm    Post subject: performance Reply with quote

hi monte,

first: this plugin is superb!! thanks.

I have two questions:
1.) is there a way to support search engine friendly urls? e.g.: mypage/search/10, where 10 means the next field.

2.) Is it true, that the pagination engine creates a full array of all pages internally? At least I see this in the smarty debugging console. Whenever I have a bigger total size (>1000 items, limit 10), pagination slows down, because of creating the whole array.

is there a way to overcome the creation of the full array?

thanks
stot
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


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

PostPosted: Sun Jun 21, 2009 5:46 pm    Post subject: Reply with quote

1) not directly, you would need to extract the vars from the PATH_INFO and assign them to $_GET values manually. Or, change the library code to support it.

2) No, the examples are just using arrays as the source data. You would normally be using SQL with query limits set.
Back to top
View user's profile Send private message Visit poster's website
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 -> Add-ons All times are GMT
Goto page Previous  1, 2, 3, 4  Next
Page 2 of 4

 
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