We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37638
    • 63 Posts
    I have a snippet that creates two documents, sets basic info including aliases, sets them as published and then saves them. However, when the calling snippet/resource tries to create a URL for the new document my error log starts showing:

    [2012-06-14 16:20:06] (WARN @ /index.php) `523` was requested but no alias was located.
    [2012-06-14 16:20:06] (WARN @ /index.php) `523` was requested but no alias was located.
    [2012-06-14 16:20:06] (WARN @ /index.php) `525` was requested but no alias was located.
    [2012-06-14 16:20:06] (WARN @ /index.php) `525` was requested but no alias was located.


    If I create a new document that just contains
    [[~525]]
    the link is correct. To the best of my knowledge the FURL is unique.

    Is this a problem with trying to get the URL before its been saved to the database or something else?

    The relevant calling resource code:

    [[!createDownloadPage?
    &item=`[[!getGet? &key=`downloadID`]]`
    &parent=`353`
    &ph=`link`
    &md5criteria=`[[!getGet? &key=`emailAddress`]]-[[!phpTime? &format=`Uu`]]`
    &pagetitle=`Free Download for [[!getGet? &key=`firstName`]] [[!getGet? &key=`lastName`]]`
    &firstName=`[[!getGet? &key=`firstName`]]`
    &timeout=`1440`
    ]]
    
    ...
    
    [[[[[[~[[+link]]]]]]]]
    [[+link]]


    Relevant code for createDownloadPage

    $linkParams = array (
      'parent' => 65,
      'timeout' => $timeout,
      'md5critera' => $md5criteria .  'link',
      'item' => $modx->getOption('item', $scriptProperties)
      );
    
    $downloadID = $modx->runSnippet('createDownloadLink', $linkParams);
    
    $contentParams = array(
      'firstName' => $firstName,
      'downloadLink' => $modx->makeURL($downloadID)
      );
    			      
    $content = $modx->getChunk('freeDownloadPage', $contentParams);
    			      
    $oDoc = $modx->getObject('modResource', $itemId);
    
    $parentDoc = $modx->newObject('modResource');
    $parentDoc->set('alias', sha1($md5criteria));
    $parentDoc->set('pagetitle', $oDoc->get('pagetitle') . ' Download');
    $parentDoc->set('parent', $parent);
    $parentDoc->set('published', 1);
    $parentDoc->set('container', 1);
    $parentDoc->set('richtext', 0);
    $parentDoc->set('template', 10);
    $parentDoc->set('publishedon', time());
    $parentDoc->set('unpub_date', ($timeout*60) + date('U'));
    $parentDoc->save(120);
    
    $doc = $modx->newObject('modResource');
    $doc->set('pagetitle', sha1($md5criteria));
    $doc->set('alias', sha1($md5criteria));
    $doc->set('published', 1);
    $doc->set('parent', $parentDoc->get('id'));
    $doc->set('searchable', 0);
    $doc->setContent($content);
    $doc->set('publishedon', time());
    $doc->set('cacheable', 0);
    $doc->set('template', 10);
    $doc->set('unpub_date', ($timeout*60) + date('U'));
    
    $doc->save(90);
    $modx->setPlaceholder($ph, $doc->get('id'));
    


    The createDownloadLink snippet is nearly identical. The resources are being correctly created, with aliases and all.

    Edit: The link placeholders in the calling document ARE populated correctly, except that a link isn't actually created. Instead, the log shows:
    [2012-06-14 17:36:17] (ERROR @ /index.php) `[[+link]]` is not a valid integer and may not be passed to makeUrl()
    [ed. note: jmaddington2 last edited this post 14 years, 4 months ago.]
      • 3749
      • 24,544 Posts
      Assuming that the context of the page is 'web' (IOW, it will appear under the web icon in the tree), try this before the makeUrl() call:


      $modx->reloadContext('web');



      That should refresh the documentMap and make the alias available.


      ------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using.
      MODX info for everyone: http://bobsguides.com/modx.html
        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
        • 37638
        • 63 Posts
        Perfect!

        Thanks Bob! I literally spent hours trying to figure this one out...
          • 9439
          • 90 Posts
          Brilliant! Had same problem, was also scratching my head for hours. Should have learned by now to look in the forum first.
            David Heriot
            pfsmedia