We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38689
    • 14 Posts
    How can I pass a URL variable to a MODx document if I'm using Friendly URLs?

    For example, epcalendar.php?mo=06&yr=2014 should show June 2014 on my calendar page, but the parms are ignored and it displays the current month.

    Another file, created outside of MODx and uploaded to the server, epc_test.php?mo=06&yr=2014 displays the proper month.


    Thank you [ed. note: pogopogo last edited this post 13 years, 11 months ago.]
      • 4172
      • 5,888 Posts
      you would do it this way:

      [[~99? &mo=`06`&yr=`2014`]]


      while 99 is the id of you calendar-page

      on your calendar-page you would need a snippet, which includes the epcalendar.php
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 38689
        • 14 Posts
        Thanks for your help. I have tried creating a test page with a link to
        [[~67? &mo=`06` &yr=`2014`]]

        and it doesn't work. MODx sends me to the default home page. I have also tried
        [[[~67~]? &mo=`06` &yr=`2014`]]

        - and it also just sends me home.

        Are we calling a document as if it is a snippet? Or do I need to create an additional page and/or snippet?
        [ed. note: pogopogo last edited this post 13 years, 11 months ago.]
          • 18373 ☆ A M B ☆
          • 3,141 Posts
          That's Revolution syntax which is not available in Evo, I think Bruno didn't notice the forum this was in. As for generating the links you'll just have to use [~67~]?mo=06&yr=2014.

          You should just be able of using $_GET['mo'] and $_GET['yr'] in the (uncached!) snippet on the following page, but I'm not sure how that epcalendar works. It's been a while that I've done anything interesting in Evo, but I'm pretty sure nothing is stopping it from working like that.

          You are sure the epcalendar.php is a MODX resource, right? It's a bit uncommon to have friendly urls use .php, but then again it's configurable so not impossible tongue

            Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

            Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
            • 38689
            • 14 Posts
            Thanks for pointing that out! And you are right about the uncached snippet. The links are generated in a PHP script (Easy PHP Calendar) which I call from a MODx snippet. If I switch from the cached to the uncached snippet call, it works, i.e. when I display the calendar and click prev/next month, the proper month is displayed.

            However ... I have another problem ... the link becomes unruly after going through a few months, e.g. events-test.php?q=events-test.php&q=events-test.php&q=events-test.php&yr=2014&mo=5&mo=6&yr=2014&mo=7&yr=2014&mo=8&yr=2014.

            The links work, i.e. the proper month is displayed, but I'd like to simplify the links. The above url should simply be events-test.php?mo=8&yr=2014.

            I believe the 'q=filename' parm comes from the RewriteRule in the .htaccess file for Friendly URLs. However, in this case it is not required because we're not going to index.php; we're going directly to the document. For some reason MODx is also tacking on the yr and mo parms instead of
            replacing them. I need to strip off the q= parms, the extra ampersands and all but the last yr and mo parms. When I call this script from a non-MODx file, the calendar script generates nice simple links, e.g. events-test.php?mo=11&yr=2012.
              • 38689
              • 14 Posts
              I wonder if we can modify .htaccess to resolve this. This is the ReWriteRule in the .htaccess file:

              RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

              The first time I click 'next month' from events-test.php:
              events-test.php?q=events-test.php&mo=11&yr=2012

              Second time:
              events-test.php?q=events-test.php&q=events-test.php&mo=11&yr=2012&mo=12&yr=2012
                • 4172
                • 5,888 Posts
                I think, you don't need to modify the .htaccess - file, but your script, how it generates the links and how it handles the url-parameters.
                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!
                  • 38689
                  • 14 Posts
                  I have a created a new thread since I have solved my original problem:

                  https://forums.modx.com/thread/80228/friendly-urls-htaccess-and-url-parameters-evo#dis-post-442098