Class: PaginationView - class to allow for displays that will be paginated ("Previous Page", "Next Page", etc.)
Method: cacheResult() - method that will take your database results and cache them for faster retrieval
CODE:
class PaginationView extends View {
/**
* Do a "faux" caching by placing the entire resultset into a $_SESSION variable. Serialize as this might be an array of objects
*
* @access protected
* @link [url]http://us4.php.net/manual/en/function.ob-flush.php[/url]
* @see link regarding older PHP version output buffer flushing
*/
function cacheResult() { // VOID METHOD
global $section, $willPaginate, $displayItemLimit, $phpVersionInt, $projectAcronym;
foreach ($_REQUEST as $key => $val) if (!isset(${$key})) ${$key} = $val;
if ($willPaginate && (int)$displayItemLimit > 0 && (!$willKeepPageSession || $willFlushResult)) {
unset($_SESSION["${projectAcronym}_result"]);
$_SESSION["${projectAcronym}_result"] = serialize($this->result);
if ((int)$phpVersionInt > 420) {
@ob_flush(); // YOU CAN ONLY FLUSH OUTPUT BUFFER IN PHP VERSIONS 4.2+
} else { // VARIATION OF OUTPUT BUFFER FLUSHING IN PHP < 4.2+
@ob_end_clean();
@ob_start();
}
clearstatcache();
}
}
}
This class and method works just fine, except that there is a potential flaw in my code logic if I use this in PHP versions older than 4.3.0. I wind up getting "trash" outputted to the output buffer, causing "null warnings" to appear on my page if I replace "ob_end_clean()" with "ob_end_flush()". What I want to do is to flush content OUT of the output buffer to ensure that I am "flushing the cache" to display fresh new results if need be.
In PHP 4.3.0+ there are no problems with this method, however, there are with older PHP versions and my code is required to be compatible with PHP as old as 4.1.2.
Any suggestions?
Thanks
Phil