Skip to content

Instantly share code, notes, and snippets.

@netProphET
Created May 20, 2010 14:36
Show Gist options
  • Save netProphET/407630 to your computer and use it in GitHub Desktop.
Save netProphET/407630 to your computer and use it in GitHub Desktop.
<?php
require_once dirname(dirname(__FILE__)) . '/inc/sys.inc';
require_once XPDO_PATH . '/xpdo.class.php';
session_start();
$xpdo= new xPDO(XPDO_DSN,XPDO_DBUSER,XPDO_DBPW, array(
xPDO::OPT_CACHE_DB=> true,
xPDO::OPT_CACHE_DB_COLLECTIONS=> true,
xPDO::OPT_CACHE_PATH=> CACHE_PATH,
xPDO::OPT_HYDRATE_RELATED_OBJECTS=> true,
xPDO::OPT_LOADER_CLASSES=> array('Country')
));
// Set the package name and root path of that package
$xpdo->setPackage(XPDO_PACKAGE, XPDO_OM_PATH);
//$xpdo->setDebug(true);
$cache = $xpdo->getCacheManager();
echo "<p>xPDO scaffolding in place. Memory usage: " . memory_get_usage() . "</p>\n";
/**
* get templated output iterating over collection of xPDOObjects without loading them all into memory at once
*
* @uses xPDOObject::iterateCollection()
* @param string $className Name of the class to search for instances of.
* @param string $template template string
* @param object|array|string $criteria An xPDOCriteria object or an array
* search expression.
* @param mixed $cacheFlag If an integer value is provided, this specifies
* the time to live in the result set cache; if cacheFlag === false, caching
* is ignored for the collection and if cacheFlag === true, the objects will
* live in cache until flushed by another process.
* @return array|null An array of class instances retrieved.
*/
function renderCollection($className, $template, $placeholder_prefix = '', $criteria= null, $cacheFlag= false) {
global $xpdo;
$output = '';
$loader = $xpdo->getObjectLoader($className, 'iterateCollection');
$output= call_user_func_array($loader, array(& $xpdo, $className, $template, $placeholder_prefix, $criteria, $cacheFlag));
return $output;
}
$output = renderCollection('Country', "<p>code: [[+code]] name: [[+name]]</p>\n", '', null, false);
echo "<p>Model operations complete. Memory usage: " . memory_get_usage() . "</p>\n";
echo $output;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment