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

    Is there a way to get the current document resource before the
    handleRequest method has been executed? The problem is that I don’t
    want the HTML output, just the object to work with.

    Example:


    <?php
    include 'path/to/modx/class';
    $modx = new modX();
    
    
    <!-- Other core code and paths -->
    
    $modx->initialize('web');
    
    include 'page/that/needs/the/current/page/resource'; // The resource id is needed here.
    
    $modx->handleRequest(); // This will expose the resource id in the $modx object, but renders the page as well which is not intended in this case.
    ?>
    


    It seems like modx firstly exposes the documentIdientifier after the
    handleRequest method has been executed. Is there a way to sidestep that
    generated output and just retrieve an object?

      • 22303 MODX Staff
      • 10,725 Posts
      No, handleRequest is responsible for handling routing to the Resources, including determining the proper target based on the request parameters, user data, and more.

      Perhaps you should explain what you are trying to do.
        • 5752
        • 10 Posts
        Quote from: OpenGeek at Mar 14, 2011, 01:28 PM

        Perhaps you should explain what you are trying to do.

        Simply, I need access to the current page resource before anything is rendered/outputted. I’ve tried some various ways, but these
        does not work. For example, create a new page and make it a child of the current page. I know that I simply could add an hidden input field that holds the current page id, but that’s an extra field that wouldn’t be necessary.


        Simple example:
        
        $modx = new modX();
        $modx->initialize('web');
        
        if($_POST['comment'])
        {
           $currentDoc = $modx->documentIdentifier;  // NULL. How to get access at this state to the document resource.
           save_data($_POST['newPage'], $currentDoc); 
        }
        
        $modx->handleRequest();

          • 22303 MODX Staff
          • 10,725 Posts
          Can you not write a Plugin to execute OnHandleRequest, or OnWebPageInit or a similar event in the process? And when I asked for what you are trying to do, I meant what are you trying to accomplish. I didn’t really mean what approach are you using to do whatever it is you want to do.

          Also, documentIdentifier is deprecated and will be gone in 2.1.x+, so I would suggest using resourceIdentifier. But again, this is not an appropriate variable for what it seems like you are trying to do.
            • 15900
            • 0 Posts
            Hi everybody,

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

            Is there a way to obtain a resource object starting from its entire path?

            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

              • 24865
              • 289 Posts
              You could try accessing the $_REQUEST[’q’] and get it from the $modx->aliasMap. That was you’ll have the right object right away. Methods for alias backwards engineered do not exist, as they would require a huge load to simply get one resource (your example would require 4 queries, whereas the aliasmap would require 1 (or rather, a lot more, but that’s being done anyway).
                @MarkGHErnst

                Developer at Adwise Internetmarketing, the Netherlands.