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 update the modx instance after that the handleRequest method has been run? I’ve got a script that creates new pages and it’s dependent on having a modx instance available to function (check for parent id etc.). The drawback, in my case, is that the new document doesn’t show up in the navigation menu as, the new page wasn’t created when modx was initialized. Is there a way to refresh or process the document output once again to have the newly created page available in the navigation menu directly?

    Consider this:

    1. $modx->handleRequest(); # Modx are aware of all current pages available.
    2. Within a template, I’ve included a PHP script that creates a new document via the modx API.
    3. Refresh the modx instance so that the new page could be present in the navigation.
    4. Page is rendered.

    There must be a way to refresh the instance before any output is generated. Just haven’t figured it out. Any help would be appreciated.

    Thanks!
      • 3749
      • 24,544 Posts
      Try this:

      $cacheManager= $modx->getCacheManager();
      
      $modx->cacheManager->refresh();


        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
        • 5752
        • 10 Posts
        Thanks Bob, but it did not work. I’m running a Modx Revolution instance and according to the API documentation, there is no refresh method of the cacheManger class.

        Is there another way to achieve this? I’ve tried to re-initialize the instance, but that didn’t work either.

        In addition, I’ve evaluated the beforeRender and beforeRequest etc. but the current resourceIdentifier isn’t present during this state.

        Do you have any other ideas?
          • 3749
          • 24,544 Posts
          I found that code in 2.1.0 rc3.

          There is another way to clear the cache, I’ll look it up later when I’m at the computer. You could also look at the code in the NewsPublisher class file, which uses the create processor (a better method for creating docs).

          I think you can forward the user to an intermediate page, then on to where you want them. That will refresh the cache map.
            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