We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10897
    • 7 Posts
    I’ve found that in MODx 0.9.6.3 DocumentParser class function RewriteUrls() doesn’t call $this->MakeUrl(), but does the same work itself.
    Result is unexpected for me, because MakeUrl() inserts $config[’base_url’] in the path, but RewriteUrls does not. So, in snippet calls
    echo "[~1~]";

    and
    echo $modx->makeUrl(1);

    have different results (in second way path will begin with $base_url).

    Why is it so? Is it bug or feature?
      • 10897
      • 7 Posts
      I’ve solved this problem by writing plugin binded OnParseDocument event:
      $in = '!\[\~([0-9]+)\~\]!ise'; // Use preg_replace with /e to make it evaluate PHP
      $out = "\$modx->makeUrl(" . '\\1' . "')";
      $modx->documentOutput = preg_replace($in, $out, $modx->documentOutput);
      
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        Snippet tags are not for use in PHP code, they are for use in the HTML code (instead of <?php ... ?> tags). You use the API ($modx->function()) in PHP code.
          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
          • 10897
          • 7 Posts
          This was an example. The fundamental problems are:
          1) duplication of the same code in two different functions in document parser class
          2) unexpected for users difference between these two imlementations
            • 3749
            • 24,544 Posts
            Quote from: Glad at May 16, 2009, 06:14 AM

            I’ve found that in MODx 0.9.6.3 DocumentParser class function RewriteUrls() doesn’t call $this->MakeUrl(), but does the same work itself.
            Result is unexpected for me, because MakeUrl() inserts $config[’base_url’] in the path, but RewriteUrls does not.

            I think you’ve answered your own question here. Two different functions, with two different names, do two different things -- no surprise there.

            rewriteUrls() is an internal function, not part of the API. It’s only called twice in the code from within the document parser when a URL without the base_url prepended is wanted.
              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