We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 35176
    • 193 Posts
    hi, how can i create a php file? i created a php content type, and then created a document resource of type php. Instead of executing and returning html to my browser, it just download to my computer. Tried with a Static Resource, same result.

    or, how can i upload a php file? it’s disallowed.

    or, how can i pass a url argument/parameter to a php snippet in a html document from the url line?

    thanks!
      jealousy<>love
      • 3749
      • 24,544 Posts
      All PHP code in MODX has to be in a snippet or plugin. It makes the site much more secure.

      Just create a snippet called MySnippet, put the PHP code in it, and put this tag on the page:

      [[!MySnippet]]


      The code will execute when the page is visited.
        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
        • 35176
        • 193 Posts
        thanks, i got that far.

        but cannot get a url param into the php.

        trying $_GET["name"], but not working.

        trying with the getUrlParam plugin, but not working. probably my mistake:

        in the snippet:
        <?php Print  [[getUrlParam? &name=`name`]]; ?> 


        in my url:
        http://silverlake.flexihostings.net/~bayviewf/modx2/index.php?id=37&name='banana'


        the returned page:

        Parse error: syntax error, unexpected ’[’ in /home/bayviewf/public_html/modx2/core/cache/elements/modsnippet/5.include.cache.php on line 7
          jealousy<>love
          • 35176
          • 193 Posts
          hey, wait, i got GET workin’!

          snippet:
          <?php
          echo 'Hello ' . $_GET["name"] . '!';
          ?>


          so why do i need the geturlparam plugin?
            jealousy<>love
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            MODx uses a templating system to manage all dynamic content. PHP code is handled via snippets (tags in the HTML), plugins (code that interrupts normal processing to override core functioning) or TVs using @EVAL binding.

            In Evo, snippet code is passed through the PHP eval() function, with snippet parameters loaded into the GLOBAL array. In Revo, snippet code is written to file then included. Not sure how Revo handles snippet parameters.

            Since the HTML is loaded from the database, any PHP directly in the HTML won’t get run; it’s not a .php file so it doesn’t trigger the PHP interpreter. However, snippets themselves can have HTML with inline PHP as is normal with .php files. I’m also pretty sure that if you use a snippet to include your template (the Manager’s template field only has a snippet, and that snippet only has the include directive) the file that is included can be HTML and inline PHP.
              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
              • 3749
              • 24,544 Posts
              Quote from: johnywhy at May 15, 2011, 01:45 AM

              hey, wait, i got GET workin’!

              snippet:
              <?php
              echo 'Hello ' . $_GET["name"] . '!';
              ?>


              so why do i need the geturlparam plugin?

              You don’t necessarily, but it will sanitize the input for you and let you limit the values. I think it’s a snippet rather than a plugin.
                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