We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19872
    • 1,078 Posts
    I have a container resource, where I use getResources to collect some text and and image from TV on my resources, and just switched my call from !getResources? to !pdoResources?.
    My page with content loads fine, but now there is a pesky error in the MODx error log.

    [2015-02-26 15:45:52] (ERROR @ .../pdotools/model/pdotools/pdofetch.class.php : 408) PHP warning: array_key_exists() expects parameter 2 to be array, null given


    Does anyone know what this error means? How can I fix it.


     [[!pdoResources?
        &parents=`[[*id]]`
        &tpl=`propsFeatured-docs-thumb-tpl`
        &limit=`0`
        &sortdir=`DESC`
        &includeTVs=`propPrice, propNeighborhood, propTitle, propImage_main`
        &processTVs=`propPrice, propNeighborhood, propTitle, propImage_main`
        &TVprefix=``
        &includeContent=`1`
        &depth=`1`
        &showHidden=`1`
        &sortbyTV=`propPrice`
        ]]

    This question has been answered by multiple community members. See the first response.

      • 3749
      • 24,544 Posts
      This looks like a bug to me, but the code is very complex and it's difficult to be sure.

      Here's line 408 of that file:

      if (!empty($this->config['sortbyTV']) && !array_key_exists($this->config['sortbyTV'], $tmp['sortby'])) {


      The error is saying that $tmp['sortby'] is not an array.

      I'm guessing here, but I would try changing it to this:

      if (!empty($this->config['sortbyTV']) && !array_key_exists($this->config['sortbyTV'], $tmp)) {


      I think that will eliminate the error. I'm not sure it will give you the correct results, but it looks to me like that's what was intended.



        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
        • 19872
        • 1,078 Posts
        Hi Bob: Thank you for looking at this. If it has to do with sort, then perhaps it has to do with my call and/or the contents of the field that is being sorted.

        &sortbyTV=`propPrice`

        The input on that TV is "Text" Output is Default.
        Since it's a price, I might change the input to "Number" and see if that has any affect.

          • 3749
          • 24,544 Posts
          I don't think that will help. The code mainly has to do with the &sortby property and what happens when it's empty.

          The code above goes to a lot of trouble to set the $tmp variable based on the &sortby property, so I suspect that line 408 is supposed to use $tmp rather then $tmp['sortby'], which as far as I can tell, is never set (hence the error).
            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
            • 19872
            • 1,078 Posts
            Made the change. Did not fix the error. However — I notice the properties are being listed lowest to highest, and my intent was highest to lowest.

            &sortdir=`DESC` Perhaps DESC is not correct? I tried DSC, but then nothing loads.

            Docs for pdoTools only says ASC is default. But then what is the abbreviation for Descending? Hmmm?
            • DESC is correct.
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
              • discuss.answer
                • 3749
                • 24,544 Posts
                I think that value is passed directly to MySQL, so it should be DESC. Did you clear the cache fully before testing the change?

                I've filed a bug report at GitHub, so we'll see what the author has to say.
                  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
                  • 19872
                  • 1,078 Posts
                  DESC is what I originally had inserted, but the sort order is still ASC. Am I missing something?
                  If the TV is Number (a price only — the $ symbol is on the template, then DESC should be most expensive to least expensive, correct?

                  Initially I had this set up with getResources and no errors were occurring. Maybe I should switch back to that?
                    • 19872
                    • 1,078 Posts
                    Something is out of wack. Regardless of DESC or ASC, there is no rhyme or reason to the order. It's neither perfect ascending or descending order. I am perplexed.
                      • 3749
                      • 24,544 Posts
                      You might try adding &sortdirTV=`DESC`
                        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