We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3496
    • 101 Posts
    I’m creating some MODx resources (documents) in a PHP-script - but some of the documents need to refer to each other.
    I’m trying to use makeUrl to get a reference to the new documents, but according to makeUrl the new (and saved) documents do not exist yet.
    The cause of this seems to be that the documents do not yet show up in modx->resourceListing.
    I did run clearCache().
    Is there something else I need to do to get the right output from makeUrl?
    Thanks for any suggestions...
      • 22303 MODX Staff
      • 10,725 Posts
      Quote from: Black at Mar 04, 2010, 05:49 AM

      I’m creating some MODx resources (documents) in a PHP-script - but some of the documents need to refer to each other.
      I’m trying to use makeUrl to get a reference to the new documents, but according to makeUrl the new (and saved) documents do not exist yet.
      The cause of this seems to be that the documents do not yet show up in modx->resourceListing.
      I did run clearCache().
      Is there something else I need to do to get the right output from makeUrl?
      Thanks for any suggestions...
      Can you share the code?
        • 3496
        • 101 Posts
        I’ve made a short test script to show what is going wrong. See attachment.
          • 22303 MODX Staff
          • 10,725 Posts
          Right, there is no difference here from the Evolution behavior; the URL is not going to be valid until the next request is made because the new data you just saved is not yet in the context cache where the URLs are defined. We might be able to add the capability to reload the current context data manually in the same request, but I recommend just doing a redirect to the same page or another location after adding the Resource to avoid this problem for now:

          On a side note, to set the "content" of a Resource, use:
          <?php
          $resource->setContent('This is a test page');
          ?>

          This will be critical once we start introducing content versioning and localization features in the core. Your code should never access $_fields; if you find you think you need to access $_fields, then you likely need to enter a bug report for MODx or xPDO.
            • 3496
            • 101 Posts
            The behaviour is indeed the same as in Evolution. I must admit I don’t really understand all you’re saying, but it sounds like you’re saying it’s impossible to get the URL of a document right after it was created (during one PHP-run) - and that is what I need to do. I’m creating severall pages during one PHP-run - and some of the pages need to contains links to some of the other pages. So perhaps I just need to write my own (simplified) makeUrl.

            I’ll change my code for setting the content. Thanks for the advise!
              • 22303 MODX Staff
              • 10,725 Posts
              Quote from: Black at Mar 07, 2010, 10:40 AM

              The behaviour is indeed the same as in Evolution. I must admit I don’t really understand all you’re saying, but it sounds like you’re saying it’s impossible to get the URL of a document right after it was created (during one PHP-run) - and that is what I need to do. I’m creating severall pages during one PHP-run - and some of the pages need to contains links to some of the other pages. So perhaps I just need to write my own (simplified) makeUrl.
              Back up; if the issue is they need to contain links, shouldn’t they simply be inserting "[[~{$resource->get(’id’)}]]" into the content? Are you saying you want to insert the generated URLs as hardcoded links into the content of subsequent Resources being added by your script?
                • 3496
                • 101 Posts
                Euh... You’re completely right.
                Thanks!
                (sorry, I’m still a bit of a novice)