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

    I posted a similar question a few months back and I think at the time Bob mentioned that the best solution was creating a plugin.

    I wanted to ask if there was any update / change to this in the new revolution.

    I have a snippet that is creating a page when the user submits a document.

    Just for cleanliness as there are hundreds of pages being created they are under a folder.

    Is there any way I can get modx to auto-free a URL and set it to the alias when a page is created?

    Any info appreciated.

    $doc = $modx->newObject('modResource');
    $doc->set('createdby', $currentUser);
    $profile = $modx->user->getOne('Profile');
    $pagetitle = $profile->get('fullname');
    $docAlias = $modx->user->get('username');
    $doc->set('parent',$parent);
    $doc->set('pagetitle',$pagetitle);
    $doc->set('alias',$docAlias);
    $doc->set('published', '1');
    $doc->set('template', '7');
    $doc->save();
    

    This question has been answered by smcilreavy. See the first response.

    [ed. note: smcilreavy last edited this post 14 years, 9 months ago.]
      • 3749
      • 24,544 Posts
      This should do it (untested):

      $doc->set('uri', $docAlias . '/');
      $doc->set('uri_override', true);
      [ed. note: BobRay last edited this post 14 years, 9 months ago.]
        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
        • 27716
        • 126 Posts
        Hi Bob,

        Thanks so much for the suggestion!

        I tried this in the snippet and it fell over. I will probably upgrade in the next day or two as m still on 2.1.3, and test it again then.

        Stuart [ed. note: smcilreavy last edited this post 14 years, 9 months ago.]
          • 3749
          • 24,544 Posts
          Sorry, there was a comma missing in my code. Try the corrected version from the post above.
            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
          • discuss.answer
            • 27716
            • 126 Posts
            Hi Bob,

            Thank you!

            Worked a treat. That's one more finicky little task automated out of my life smiley

            Stuart