View previous topic :: View next topic |
Author |
Message |
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed May 30, 2007 1:39 pm Post subject: SmartyPaginate 1.6 released |
|
|
Changes since 1.5:
* fix bug in paginate_middle, link not showing when item_total
= n*limit-1 (danw, monte)
* fix NOTICE messages in paginate_middle (Temas, monte)
http://www.phpinsider.com/php/code/SmartyPaginate/ |
|
Back to top |
|
IGonza Smarty Rookie
Joined: 14 Jan 2007 Posts: 17
|
Posted: Mon Jun 11, 2007 7:16 pm Post subject: |
|
|
Hello,
I have a small question. As I see in your demo version (http://www.phpinsider.com/php/code/SmartyPaginate/demo/) the middle part shows just 4 items. For example, [41-50][51-60][61-70][71-80]. How can I set up the number of them?
I try to use this class with POST vars and get a problem. I see all items between prev and next parts. And it looks like [1-25][26-50] and all other until [2500-2525] - my last range.
How to fix it? Maybe I lost some session variable?
Thanks,
Igor. |
|
Back to top |
|
IGonza Smarty Rookie
Joined: 14 Jan 2007 Posts: 17
|
Posted: Mon Jun 11, 2007 7:36 pm Post subject: |
|
|
Ok, I found that setPageLimit() does it.
You sample code at http://www.phpinsider.com/php/code/SmartyPaginate/ doesn't contain setPageLimit() but demo code uses it. I would add that function to sample.
Thanks,
Igor |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Jun 11, 2007 9:20 pm Post subject: |
|
|
The docs include setPageLimit(), look again. |
|
Back to top |
|
IGonza Smarty Rookie
Joined: 14 Jan 2007 Posts: 17
|
Posted: Mon Jun 11, 2007 9:28 pm Post subject: |
|
|
yes, I saw it. I'm about your demo example.
Code: |
index.php
---------
session_start();
require('Smarty.class.php');
require('SmartyPaginate.class.php');
$smarty =& new Smarty;
// required connect
SmartyPaginate::connect();
// 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)
$_data = range(1,100);
SmartyPaginate::setTotal(count($_data));
return array_slice($_data, SmartyPaginate::getCurrentIndex(),
SmartyPaginate::getLimit());
}
|
There is not setpagelimit(). But demo site works with it. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Jun 11, 2007 9:52 pm Post subject: |
|
|
That is just a short usage synopsis, there are only a small number of functions shown there. |
|
Back to top |
|
IGonza Smarty Rookie
Joined: 14 Jan 2007 Posts: 17
|
|
Back to top |
|
tdmf Smarty Rookie
Joined: 24 Jul 2006 Posts: 21
|
Posted: Wed Jun 20, 2007 5:31 pm Post subject: {$paginate.current_item} - not for multiple pagination sets |
|
|
Hey there,
i'm using different instances of pagination with your script on my site.
All items have their unique id and everything is fine so far.
In the template i can easily trigger each set with its appropriate ID
e.g. {paginate_first id="mydata"}.
In my case i'm outputting browsable tables via pagination.
I included a function to dynamically set the sorting order with "ASC", "DESC" and for this link i need {$paginate.current_item}.
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 ?
Please let me know if im mistaken here!
Thanks a lot - I do very much appreciate your work on smarty_paginate. |
|
Back to top |
|
devi Smarty n00b
Joined: 02 Aug 2007 Posts: 1
|
Posted: Thu Aug 02, 2007 12:36 am Post subject: |
|
|
This add-on is extremely nifty! Thank you for making it!
One small request, would you please change the "text" parameter to use the attribute "title" instead of "text" in the output? |
|
Back to top |
|
kills Smarty Elite
Joined: 28 May 2004 Posts: 493
|
Posted: Mon Aug 06, 2007 11:26 am Post subject: |
|
|
hi monte,
i added a prefix and a suffix for the current page in the paginate_middle function:
Code: |
function smarty_function_paginate_middle($params, &$smarty) {
$_id = 'default';
$_prefix = '[';
$_suffix = ']';
$_link_prefix = '';
$_link_suffix = '';
$_current_prefix = '';
$_current_suffix = '';
$_page_limit = null;
$_attrs = array();
if (!class_exists('SmartyPaginate')) {
$smarty->trigger_error("paginate_middle: missing SmartyPaginate class");
return;
}
if (!isset($_SESSION['SmartyPaginate'])) {
$smarty->trigger_error("paginate_middle: SmartyPaginate is not initialized, use connect() first");
return;
}
foreach($params as $_key => $_val) {
switch($_key) {
case 'id':
if (!SmartyPaginate::isConnected($_val)) {
$smarty->trigger_error("paginate_middle: unknown id '$_val'");
return;
}
$_id = $_val;
break;
case 'prefix':
$_prefix = $_val;
break;
case 'suffix':
$_suffix = $_val;
break;
case 'current_prefix':
$_current_prefix = $_val;
break;
case 'current_suffix':
$_current_suffix = $_val;
break;
case 'link_prefix':
$_link_prefix = $_val;
break;
case 'link_suffix':
$_link_suffix = $_val;
break;
case 'page_limit';
$_page_limit = $_val;
break;
case 'format':
break;
default:
$_attrs[] = $_key . '="' . $_val . '"';
break;
}
}
if (!isset($_SESSION['SmartyPaginate'][$_id]['item_total'])) {
$smarty->trigger_error("paginate_middle: total was not set");
return;
}
if(!isset($_page_limit) && isset($_SESSION['SmartyPaginate'][$_id]['page_limit'])) {
$_page_limit = $_SESSION['SmartyPaginate'][$_id]['page_limit'];
}
$_url = $_SESSION['SmartyPaginate'][$_id]['url'];
$_total = SmartyPaginate::getTotal($_id);
$_curr_item = SmartyPaginate::getCurrentItem($_id);
$_limit = SmartyPaginate::getLimit($_id);
$_item = 1;
$_page = 1;
$_display_pages = 0;
$_ret = '';
$_attrs = !empty($_attrs) ? ' ' . implode(' ', $_attrs) : '';
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 ));
}
$_item = ($_item_start >= 1) ? $_item_start : 1;
$_page = ceil($_item / $_limit);
}
while($_item <= $_total) {
if(isset($params['format']) && $params['format'] == 'page') {
$_text = $_prefix . $_page . $_suffix;
} else {
$_text = $_prefix . $_item . '-';
$_text .= ($_item + $_limit - 1 <= $_total) ? $_item + $_limit - 1 : $_total;
$_text .= $_suffix;
}
if($_item != $_curr_item) {
$_this_url = $_url;
$_this_url .= (strpos($_url, '?') === false) ? '?' : '&';
$_this_url .= SmartyPaginate::getUrlVar($_id) . '=' . $_item;
$_ret .= $_link_prefix . '<a href="' . str_replace('&', '&', $_this_url) . '"' . $_attrs . '>' . $_text . '</a>' . $_link_suffix;
} else {
$_ret .= $_link_prefix . $_current_prefix . $_text . $_current_suffix . $_link_suffix;
}
$_item += $_limit;
$_page++;
$_display_pages++;
if(isset($_page_limit) && $_display_pages == $_page_limit)
break;
}
return $_ret;
} |
Would be nice to have this feature in the next release..
Bye,
Markus |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Aug 06, 2007 1:20 pm Post subject: |
|
|
added to CVS, thanks! |
|
Back to top |
|
necro_smarty Smarty n00b
Joined: 27 Aug 2007 Posts: 1
|
Posted: Mon Aug 27, 2007 2:44 am Post subject: im getting a trouble with my smarty paginate |
|
|
something trouble with my function in my smarty paginate when i call my function
this is error report:
Fatal error: Call to undefined function get_data_result()
and my function is
function get_data_result(){
//this is my query to searching a data in local database
$result=$db_genius->sql_query("select * from Tabel_Pelanggan where No_Jaringan LIKE '".$no."%' AND Nama_Pelanggan LIKE '".$nama."%' AND Alamat LIKE '".$alamat."%' AND kota LIKE '".$kota."%'");
$jumRows=$db_genius->sql_numrows($result);
// to get data i using looping
while($row=mysql_fetch_array($result,MYSQL_ASSOC)){
$_data[]=$row;
}
//get the total of data
$resultRow=count($_data);
SmartyPaginate::setTotal($resultRow);
return array_slice($_data,SmartyPaginate::getCurrentIndex(),SmartyPaginate::getLimit());
//end of function
}
maybe you can help me to solve my problem,
please send the problem solving to my email
thank you for your attention:) |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Aug 27, 2007 2:51 pm Post subject: |
|
|
Code: | Fatal error: Call to undefined function get_data_result() |
That function doesn't exist. Make sure you include the file with the function before you call it. |
|
Back to top |
|
czarnowski Guest
|
Posted: Sun Sep 02, 2007 3:31 pm Post subject: |
|
|
Your demo does not work:
Code: | Warning: main(Smarty.class.php) [function.main]: failed to open stream: No such file or directory in /var/www/www.phpinsider.com/docs/php/code/SmartyPaginate/demo/index.php on line 17
Warning: main(Smarty.class.php) [function.main]: failed to open stream: No such file or directory in /var/www/www.phpinsider.com/docs/php/code/SmartyPaginate/demo/index.php on line 17
Fatal error: main() [function.require]: Failed opening required 'Smarty.class.php' (include_path='.:/usr/share/php4:/usr/share/php') in /var/www/www.phpinsider.com/docs/php/code/SmartyPaginate/demo/index.php on line 1 |
|
|
Back to top |
|
equak Smarty n00b
Joined: 17 Mar 2008 Posts: 2
|
Posted: Mon Mar 17, 2008 4:23 am Post subject: |
|
|
really cool plugin |
|
Back to top |
|
|