We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 15900
    • 0 Posts
    Hi everybody,

    it’s my first time here and I have a little problem.

    Is there a way to obtain a resource object starting from its full alias?

    something like $modx->getResourceFromPath( ’it/page1/page2/page.html’ )

    I need to make an ajax call passing the entire path, and I need the resource object back.

    thank you very much
    alessandro
      • 22303 MODX Staff
      • 10,725 Posts
      Why can’t you use the Resource id to generate the link for your AJAX call?

      You can do something like this if you are using Friendly URLs to get a published Resource id from the path:
      <?php
      if (array_key_exists('path/of/resource.html', $modx->aliasMap) {
          $resourceId = $modx->aliasMap['path/of/resource.html'];
      }
      


      In 2.1 and later, you can also query the database for the Resource object...
      <?php
      $resource = $modx->getObject('modResource', array('uri' => 'path/to/resource.html'));
      
        • 15900
        • 0 Posts
        Thanks a lot Jason this is exactly what I was looking for!

        ale