The following generates a nested view of data. Parent is items, child is propitems.
The
API function basically grabs all items, then as it iterates the parents, it has a secondary loop that iterates related children within the parent loop:
$items = pnModAPIFunc('RentalReport',
'user',
'get');
$propitems = pnModAPIFunc('RentalReport',
'user',
'getpropbycomm');
if (!$items) {
return pnVarPrepHTMLDisplay(_EXAMPLEITEMFAILED);
}
// Create output object
$pnRender =& new pnRender('RentalReport');
$RentalReportpropitems = array [20]();
$RentalReportitems = array [21]();
foreach ($items as $item) { // Parent loop
$pnRender->assign($item);
foreach ($propitems as $propitem) { // Child loop
if ($propitem['cid'] == $item['id']) {
$pnRender->caching=false;
$pnRender->assign($propitem);
$RentalReportpropitems[] = $pnRender->fetch('RentalReport_user_proprow_read.htm', $propitem['id']);
} //End related Child
}
$pnRender->assign('propitems', $RentalReportpropitems);
$RentalReportitems[] = $pnRender->fetch('RentalReport_user_row_read.htm', $item['id']);
$RentalReportpropitems = ''; $RentalReportpropitems = array [22]();
} // End parent
$pnRender->caching=false;
$pnRender->assign('items', $RentalReportitems);
return $pnRender->fetch('RentalReport_user_view.htm');
}
Without the FALSE for the caching in the child loop, with pnRender caching turned on, then the first child record is the only one that shows...for ALL results! IN other words, every parent renders correctly, but whatever children they have do not show - the FIRST child shows in their place, over and over for every parent.
What is the right way to do this with caching? The data will not change often, so even a full cache of all parent and child items would be great.
Thanks for any insight.
UHEweb