We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1887
    • 50 Posts
    Hello

    I have a snippet called "faq_searchResult" which is throwing the 500 error. I can't identify what specific code is throwing the error. The code in the snippet itself is pretty simple, and there are no obvious errors in the snippet code. It would appear then, that somehow the getResources call that this snippet generates is somehow throwing that 500 error.

    The site is running Revo 2.2.9 and hosted on modxcloud.

    <?php
    $output = "";
    
    $faqTitle = $modx->resource->get('pagetitle');
    
    $templateid = $modx->resource->get('template');
    
    $faqId = $modx->resource->get('id');
    
       if(isset($_GET['category']) && isset($_GET['product']))
       {
          $output = '[[!getResources?
                       &tpl=`faq_tpl`
                       &parents=`'.$faqId.'`
                       &includeTVs=`1`
                       &tvFilters=`faq_category==%'.$_GET['category'].'%,faq_products==%'.$_GET['product'].'%` 
                       &limit=`0`
                       &where=`{"template:=":'.$templateid.'}`
                       &includeContent=`1`
    		   &showHidden=`1`]]';
       }
       else if(isset($_GET['category']))
       {
          $output = '[[!getResources?
                       &tpl=`faq_tpl`
                       &parents=`'.$faqId.'`
                       &includeTVs=`1`
                       &tvFilters=`faq_category==%'.$_GET['category'].'%` 
                       &limit=`0`
                       &where=`{"template:=":'.$templateid.'}`
                       &includeContent=`1`
    		   &showHidden=`1`]]';
       }
       else if(isset($_GET['product']))
       {
          $output = '[[!getResources?
                       &tpl=`faq_tpl`
                       &parents=`'.$faqId.'`
                       &includeTVs=`1`
                       &tvFilters=`faq_products==%'.$_GET['product'].'%` 
                       &limit=`0`
                       &where=`{"template:=":'.$templateid.'}`
                       &includeContent=`1`
    		   &showHidden=`1`]]';
       }
       else
       {
          $output = '[[!getResources?  
                       &tpl=`faq_tpl` 
                       &parents=`'.$faqId.'`
                       &includeTVs=`1`
                       &limit=`0`
                       &where=`{"template:=":'.$templateid.'}`
                       &includeContent=`1`
    				   &showHidden=`1`]]';
       }
    
    return $output;


    Any pointers on how to further diagnose this gratefully received.

    Kind regards

    James
      • 3749
      • 24,544 Posts
      There are no PHP syntax errors in the code, but when you do that much concatenation, it's difficult to get everything right.

      Is there anything in the MODX error log?
        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
        • 39404
        • 175 Posts
        stalemate resolution associate Reply #3, 12 years, 10 months ago
        Hi James,

        Other than the MODX error log, another place you can check on the cloud is the /log directory. If nothing shows in the MODX error log, you can also check where I specified.

        On the topic of syntax, I will gladly defer to Bob's knowledge of syntax rather than my own, but one thing to consider is that maybe it's not the snippet itself that is causing this. You can verify by simply removing the snippet from the resource to see if the error 500 still appears.

        Assuming that it is the snippet, try breaking apart the large if / else if blocks so that you're testing them one at a time. If they each work individually, then it might be how they are strung together.

        If they don't work, then try replacing all of your concatenations with string literals and then if all is still messed up, try taking out some non-required parameters.

        Hopes this gives you some ideas.

        Regards,
        Tom
          • 1887
          • 50 Posts
          It turned out to be a problem in the template that getResources was using, but many thanks for the pointers as it spurred me on to finding the fault.

          I diagnosed it by removing the outer double pair square brackets which is stored in the output so that I could see the command being run and manually tried the output from there.