We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28883
    • 35 Posts
    This may sound like a rather strange question, but is there any way to get the id of a given resource from the url?

    Almost like a reverse of makeUrl()

    Maybe my approach is just wrong? I'd appreciate any thoughts or assistance! [ed. note: supanick last edited this post 14 years, 6 months ago.]
      • 22303 MODX Staff
      • 10,725 Posts
      If it's within the current context:
      <?php
      if (array_key_exists($uri, $modx->aliasMap)) {
          $resourceId = $modx->aliasMap[$uri];
      }
      


      This must be the complete URI relative to the Context's base_url and including the Content Type extension or container_suffix, i.e. if the URL to your site is
      - http://domain.tld/path/to/resource.html
      then the URI to search for would be
      - path/to/resource.html

      You can do the same for Resources in other Contexts as well:
      <?php
      $context = $modx->getContext($contextKey);
      if (array_key_exists($uri, $context->aliasMap)) {
          $resourceId = $context->aliasMap[$uri];
      }
      
        • 28883
        • 35 Posts
        Thanks opengeek - you're the man!;)