Zikula: A Flexible Open Source Content Management System
home | forum | contact us

Dizkus

Bottom
Nested pnRender items and caching...
  • Posted: 25.04.2006, 10:50
     
    uheweb
    rank:
    Professional Professional
    registered:
     September 2004
    Status:
    offline
    last visit:
    10.11.08
    Posts:
    815
    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:



    Code

    $items = pnModAPIFunc('RentalReport',
                              'user',
                              'get');
        $propitems = pnModAPIFunc('RentalReport',
                              'user',
                              'getpropbycomm');
       
        if (!$items) {
            return pnVarPrepHTMLDisplay(_EXAMPLEITEMFAILED);
        }

        // Create output object
        $pnRender =& new pnRender('RentalReport');

     
       
        $RentalReportpropitems = array();
        $RentalReportitems = array();

        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();
            } // 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

Extensions Moderation

Main Menu

Extensions Database

Documentation

Development

Login

Donate to Zikula