We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    Did you paste your snippet call directly into the message above? If not, we should have a look at the real one. I had a similar problem once with spaces around the equals sign.

    Try changing the name of the variable, in case "input" is a reserved word.

    Make the isset statement into a regular "if" statement that prints feedback on whether input is set.

    The only other thing I can think of is that there are some quirks in cacheing and snippet calls in 0.9.6 (to be fixed in 0.9.7).

    I think if you call an uncached snippet from an uncached page, the snippet may actually be called as cached -- so you might be running an older version of your code. If none of the above suggestions work, try clearing the site cache and using [[Shoutcast? &input=`2`]] to call the snippet.

    Bob

      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
      • 9572
      • 56 Posts
      I did paste my snippet call in directly to make sure you guys could see what I was looking at. Here’s the code for the snippet;
      <?php
      //Getting the parameter from the snippet call.  The default is 0
      $input = (isset($input))? $input : 0;
      
      //This function pulls the XML file while sending a user agent to the server.
      function get_xml_specify_ua($xml_file_url,$user_agent_string)  
      {  
        $result = '';  
          $opts = array(  
            'http' => array(  
              'method'  => 'GET',  
              'header'  => "User-Agent: $user_agent_string"  
            )  
          );  
          $context  = stream_context_create($opts);  
          $result = file_get_contents($xml_file_url, false, $context);  
          
        return $result;  
      }  
      
      //Calling the above function and sending in the hardcoded parameters
      $xml = get_xml_specify_ua(  
        'http://serverurl.com:8000/admin.cgi?pass=passgoeshere&mode=viewxml&page=4',  
        'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6'  
      );  
      
      //Parsing the XML with SimpleXML
      
      $xmlData = new SimpleXMLElement($xml);
      
      //Returning the title from the location specified in $input (passed in through the snippet call)
      return $xmlData->SONGHISTORY->SONG[$input]->TITLE;
      ?>


      Am I missing something here?
        • 33372
        • 1,611 Posts
        I don’t see where you’ve included the SimpleXMLElement object class...?
          "Things are not what they appear to be; nor are they otherwise." - Buddha

          "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

          Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
          • 9572
          • 56 Posts
          Quote from: ZAP at Sep 22, 2007, 05:42 PM

          I don’t see where you’ve included the SimpleXMLElement object class...?
          SimpleXML is a built-in function in PHP5; http://us.php.net/simplexml
            • 33372
            • 1,611 Posts
            Aha. Learn something new every day. What happens if you change the last line to return $input; ?
              "Things are not what they appear to be; nor are they otherwise." - Buddha

              "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

              Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
              • 9572
              • 56 Posts
              Quote from: ZAP at Sep 22, 2007, 06:30 PM

              Aha. Learn something new every day. What happens if you change the last line to return $input; ?

              It returns the parameter passed in the call!

              Why would it be having issues with being placed in that line? Right now I literally get nothing returned so there must be a problem in this line;
              return $xmlData->SONGHISTORY->SONG[$input]->TITLE;
                • 33372
                • 1,611 Posts
                Maybe your XML data doesn’t match up to what you’re using in your return statement. Could be just a matter of case or some other annoying little detail like that. Does return $xmlData->SONGHISTORY->SONG[1]->TITLE; return anything?
                  "Things are not what they appear to be; nor are they otherwise." - Buddha

                  "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

                  Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  The last (well, the only) time I’ve used that, I had all kinds of problems until I figured out I needed some quote marks surrounding the variable at one point.
                    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
                    • 9572
                    • 56 Posts
                    Quote from: ZAP at Sep 22, 2007, 07:00 PM

                    Maybe your XML data doesn’t match up to what you’re using in your return statement. Could be just a matter of case or some other annoying little detail like that. Does return $xmlData->SONGHISTORY->SONG[1]->TITLE; return anything?
                    Yep, that does return something. I know how many cells there are in the Song array so I’ve been using values within its bounds.

                    As to the quotes around variables, do you know any more about that?
                      • 3749
                      • 24,544 Posts
                      Quote from: fegul at Sep 22, 2007, 06:47 PM

                      Quote from: ZAP at Sep 22, 2007, 06:30 PM

                      Aha. Learn something new every day. What happens if you change the last line to return $input; ?

                      It returns the parameter passed in the call!

                      Why would it be having issues with being placed in that line? Right now I literally get nothing returned so there must be a problem in this line;
                      return $xmlData->SONGHISTORY->SONG[$input]->TITLE;


                      Hmmm... If return $input returns the correct value of the parameter then the parameter is getting to the snippet ok.
                      If hardcoding the value of $input makes the snippet work then the line just above must be ok.

                      It seems to me that the only thing left is that when $input is set from the passed parameter, it’s the wrong variable type.

                      You might try casting it:

                      return $xmlData->SONGHISTORY->SONG[(int)$input]->TITLE;


                      or setting $input = 1;
                      earlier in the code -- before the assignment from the parameter -- to give it the correct type.

                      Bob

                        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