Code Comments
Programming Forum and web based access to our favorite programming groups.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 b
e show start in 1 and end in 5. I see the example that came with him but I n
ot 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 normall
y? 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 co
de? 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.
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.