We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 46876
    • 23 Posts
    Hi again guys,

    Here's another issue I stumbled upon, this time with regards to getPage. I'm trying to get getPage to connect to a custom table (from MIGX). Here is the custom snippet used:

    TestPagination Snippet:
    <?php
    $id = $modx->resource->get('id');
    
    $c = $modx->newQuery('redasNewsPackage');
    $c->where(array('resource_id' => $id));
    $c->sortby('createdon','DESC');
    
    $total = $modx->getCount('redasNewsPackage',$c);
    $totalVar = $modx->getOption('totalVar', $scriptProperties, 'total');
    
    $modx->setPlaceholder($totalVar,$total);
     
    $c->limit($limit,$offset);
     
    $collection = $modx->getCollection('redasNewsPackage',$c);
       
    foreach($collection as $item) {
        $vars = $item->toArray();
        $out[] = $modx->getChunk($tpl, $vars);
    }
       
    return implode("\n", $out);

    Somehow this code does not seem to work as getPage returns NULL. The object 'redasNewsPackage' is a custom table created in MIGX. Is the table being called correctly?

    Resource Code:
    <div class="article-results">[[!getPage? &element=`TestPagination` &tpl=`articleResults` &limit=`20` &pageLimit=`2`]]</div>
    <div class="paging"><span class="pages">Page [[+page]] of [[+pageCount]]</span> [[+page.nav]]</div>

    articleResults Chunk Code:
    <div>
        <a href="[[+file]]">[[+title]]</a>
    </div>
    


    The code is based on example found here: https://forums.modx.com/thread/?thread=79769

    Thanks!

    This question has been answered by Bruno17. See the first response.

    • discuss.answer
      • 4172
      • 5,888 Posts
      seems you didn't add your package.

      But, no need to reinvent the wheel.
      if you have installed MIGX, you can try migxLoopCollection

      [[!getPage?
      &element=`migxLoopCollection`
      &packageName=`yourPackage`
      &classname=`yourClass`
      &tpl=`yourTpl`
      &limit=`20`
      &where=`{"resource_id":"[[*id]]"}`
      &sortConfig=`[{"sortby":"createdon","sortdir":"DESC"}]`
      ]]


      you can also use pdoResources,bloX or rowboat to get it done.

        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 46876
        • 23 Posts
        As always Bruno, you are a godsend. Thank you so much! I'll be sure to buy you a beer. laugh