We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32241
    • 1,495 Posts
    Hi, can sombody guide me on how to fetch alias path using MODx API?

    I build a new calendar snippet based on db, but I need to know, how to get index.php file with all the querystring needed or virtual alias path, depending on the site config. I just need to generate link automatically in my snippet, and appended a specific query string needed by my calendar snippet.

    Hope somebody can guide me to the right direction.

    Thanks
      Wendy Novianto
      [font=Verdana]PT DJAMOER Technology Media
      [font=Verdana]Xituz Media
      • 22303 MODX Staff
      • 10,725 Posts
      You can use $modx->virtualDir to retrieve the current virtual directory when using alias paths.
        • 32241
        • 1,495 Posts
        How the code able to know whether it’s using alias path, alias, or plain querystring? Can we access the MODx configuration variables that was setup in the manager through modx object?

        Thanks
          Wendy Novianto
          [font=Verdana]PT DJAMOER Technology Media
          [font=Verdana]Xituz Media
          • 22303 MODX Staff
          • 10,725 Posts
          Absolutely Wendy, either directly in the snippet code:

          $aliasPaths= $modx->config['use_alias_path'];


          or even directly in the content (though not very useful with this particular setting):

          [(use_alias_path)]


          There is a list of available config settings at http://modxcms.com/modx-tags.html under Settings.

          However, keep in mind that the virtualDir will only have a value if you have use_alias_path set to on, so you shouldn’t have to check.
            • 32241
            • 1,495 Posts
            Jason, I did this on my snippet

            echo "documentIdentifier: ".$modx->documentIdentifier."<br />";
            echo "virtualDir: ".$modx->virtualDir."<br />";
            echo "config(use_alias_path): ".$modx->config['use_alias_path']."<br />";
            


            And here is the result

            documentIdentifier: 54
            virtualDir:
            config(use_alias_path): 1
            


            I’m using Alias Path, and it was shown in the result, but the virtualDir contain nothing in there.

            Could you help me with this?

            Thanks
              Wendy Novianto
              [font=Verdana]PT DJAMOER Technology Media
              [font=Verdana]Xituz Media
              • 32241
              • 1,495 Posts
              Another funny things that I found out

              here is the code that I use for testing

              echo "documentIdentifier: ".$modx->documentIdentifier."<br />";
              echo "virtualDir: ".$modx->virtualDir."<br />";
              echo "config(use_alias_path): ".$modx->config['use_alias_path']."<br />";
              echo "method: ".$modx->documentMethod."<br />";
              echo "method (function call): ".$modx->getDocumentMethod()."<br />";
              


              Here is the result without any SEF being turned on
              documentIdentifier: 54
              virtualDir:
              config(use_alias_path): 0
              method: id
              method (function call): id
              


              Here is the result without any alias or alias path being turned on, so using friendly url
              documentIdentifier: 54
              virtualDir:
              config(use_alias_path): 0
              method: id
              method (function call): alias
              


              Here is the result with alias turn on, but not the alias path
              documentIdentifier: 54
              virtualDir:
              config(use_alias_path): 0
              method: id
              method (function call): alias
              


              Here is the result from everything being turned on
              documentIdentifier: 54
              virtualDir:
              config(use_alias_path): 1
              method: id
              method (function call): alias
              


              What do you think about the result?
              I’m investigating the code right now, hope I found something usefull to figure out the reason behind this.
                Wendy Novianto
                [font=Verdana]PT DJAMOER Technology Media
                [font=Verdana]Xituz Media
                • 32241
                • 1,495 Posts
                So the getDocumentObject() method will never reach the search using alias, which is that’s not a big deal, because it will be redundant to search using alias, if the parser able to get documentidentifier as an id all the time. If this is what it suppose to be, than we can cleaning up some code for that method.

                So nothing wrong with setting all the method to "id" before it starts to fetch the document object.

                Sorry if I use this forum as a place for me to take anote smiley

                  Wendy Novianto
                  [font=Verdana]PT DJAMOER Technology Media
                  [font=Verdana]Xituz Media
                  • 19726
                  • 239 Posts
                  Quote from: wendy at Dec 22, 2005, 05:09 PM
                  I just need to generate link automatically in my snippet, and appended a specific query string needed by my calendar snippet.
                  If you just want to create a link to the current page with a querystring you could just use:

                  $modx->makeUrl($modx->documentObject[’id’], ’’, ’somevar=123&anothervar=456’);

                  The first param is the documentid to create a link to
                  The second one is called alias, but I never used it
                  The third parameter is the querystring
                    • 32241
                    • 1,495 Posts
                    Cool, that helps a lot.

                    Thanks Mitch.
                      Wendy Novianto
                      [font=Verdana]PT DJAMOER Technology Media
                      [font=Verdana]Xituz Media
                      • 32241
                      • 1,495 Posts
                      Btw, I misunderstand the virtualdir as the complete file path plus the filename.

                      After reading the document parser code, I just realize what will be returned by the virtualdir vars.

                      Sorry for making such a hassle.

                      Thanks for assisting me jason and mitch. I’m looking forward to bother you guys again in the future smiley
                        Wendy Novianto
                        [font=Verdana]PT DJAMOER Technology Media
                        [font=Verdana]Xituz Media