We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21677
    • 15 Posts
    Is there any reason why getCollection is driving my crazy? I return count and I get 14 resources, when run the exact raw SQL from criteria I get the correct 16 resources returned.
    $collection = $modx->getCollection('modResource', $criteria);
    return count($collection);

    Running on Revo.

    UPDATE: You’ll see the same posted below, but I figure it’d b easier to see it here. The reason I’m getting a conflict in these numbers is because 2 of the 16 documents have resource groups on them to restrict their access. I do need restricted access, but because getCount and getCollection return different results (getCount returns 16, getCollection returns 14 documents) the snippet getPage doesn’t work that well. I’m still jacking with it, but it’s all a little confusing.
      • 3749
      • 24,544 Posts
      I think there is still some quirkiness with getCollection() and document types. Are any of the resources symlinks or weblinks?

      Have you looked in the site_content table to see if there is anything different about the document types of the missing resources?
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 21677
        • 15 Posts
        I figured it out. I’ve had quite a few issues with trying to get getResources to work for me, I most have mixed a few problems up. I had a resource group on those documents that apparently was keeping it from getting found. Oops.

        Which leads me to another question. Is there a way to give getCollection permission to get those documents? I have logged in to the front-end, and there is a session stored that is allowed access to those docs, but it doesn’t make it’s way to getCollection.
          • 21677
          • 15 Posts
          Is there any good reason why [tt]$modx->getCollection(’modResource’, $criteria);[/tt] returns 14 documents while [tt]$modx->getCount(’modResource’, $criteria);[/tt] returns ’16’, its causing conflicts within paged results. Even though I set my page limit to 5, the because of this conflict my pages return these results: 4,5,4,1 (documents per page).

          Keep in mind, 2 of the 16 documents have a resource group on them that restricts their access.
            • 3749
            • 24,544 Posts
            I think that’s expected (though I could be wrong) -- getCount() simply asks how many there are that fit the criteria, getCollection() asks to retrieve them and you can’t retrieve ones that the current user is restricted from seeing.

            Would this work for you?

            $resources = $modx->getCollection('modResource',$criteria);
            $count = count($resources);


            That will give you matching numbers.
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting