We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29333
    • 26 Posts
    Hey !

    Can anyone tell me how to create using PHP in a snippet a Logout link? How about a link to another page (using page ID?) ?
    Are there functions for this inside $modx?

    Thanks! \m/ o_o \m/
      Mosh-pit rules !!!
      • 25663 MODX Staff
      • 12,272 Posts
      The WebLogin stuff and default demo content from 0.9.0 does this all. Take a peek at that. smiley
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 29333
        • 26 Posts
        WebLogin - are you referring to the WebLogin snippet?
        --------------------
        Hmm, and what about the link to a document created by me knowing its ID number ? i need to make it as a portion of a snippet, so I cannot call (i think) another snippet from inside a snippet. for this I would only need to know the .php document i should call, its path and the necessary parameters...

        any ideas ? huh
          Mosh-pit rules !!!
          • 22303 MODX Staff
          • 10,725 Posts
          Links to documents can easily be created by either outputting...
          "[~$documentId~]"

          in your snippet, where $documentId is the ID of the page, OR you can create a links using the function makeUrl, as in...
          $documentLink= $modx->makeUrl($documentId)

          You can also specify an $alias as a second parameter (though this isn’t really necessary or useful it seems), and the query string to append as the third parameter, e.g.
          $documentLink= $modx->makeUrl($documentId, '', '?param1=value1&param2=value2')


          Re: weblogin, yes the weblogin snippet demonstrates how to login and logout to the MODx site as a web user, including creating a logout link, if the user is already logged in. You won’t be calling the snippet, I don’t think, unless you want a login form to appear if they aren’t logged in, versus the logout link. In this case, take a look at what we did in the default site content, to present a document called login OR logout (depending on the user state) in the menu and using a placeholder assigned by a TV with an @EVAL script to title the document.

          For what it is worth, future versions will have a better user/authentication API so you can more easily create custom logout links, etc.