| Reynier Perez Mira 2005-04-11, 4:02 pm |
| Well list, I found SmartyPaginate Plugin on Smarty Plugins Repository and I need to use him beacuse I have a Guestbook in my site and the results must be show start in 1 and end in 5. I see the example that came with him but I not understand some things. Take a look to example:
File: 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(),Smarty
Paginate::getLimit());
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
In first: Why Smarty is instance $smarty object by reference and not normally? I see this in considerably examples. The second is: If a try to paginate results from a query, where is the query? I not see them into the example code? Where they should stay?
Regards
Reynier Pérez Mira
3ero. Ing. Informática
Entre más inteligente me siento, más me doy cuenta de lo ignorante que soy.
|