Amazing. that does work. Care to explain how its working? What in that chunk is telling the Weblogin snippet to swap messages based on login status?
And second. Does anyone know if the personalize snippet can display the full name if available rather than a user ID?
-
☆ A M B ☆
- 24,524 Posts
It’s the [+personalize+] placeholder. The personalize snippet loads its output into the placeholder with that name (if you specified that option in the snippet call), and it gets displayed wherever you put the placeholder. You can even have the placeholder in more than one place, and use it in any chunk, template, or document content you like.
The snippet could display anything you like. It uses the modx class function
$test = $modx->getLoginUserName();
which returns the $_SESSION[’webShortname’].
But it could grab the value desired directly from the SESSION all by itself.
$test = $_SESSION['webFullname']);
And how hard would it be to add a selector to the Personalize snippet so that you could choose which data field it pulled the name from. Or I suppose it could then be address, birthday, or whatever.
-
☆ A M B ☆
- 24,524 Posts
Well, as it is, it only gets data from the SESSION, so we’re talking some serious database queries here to access two or three tables for the data on the current user. Doable, but I doubt if you’ll see it soon.
-
☆ A M B ☆
- 24,524 Posts
SESSION is an array used by PHP for session persistance, since TCP/IP is a "stateless" protocol. The web server doesn’t know you or anything at all about you from one page request to another, so some means has to be used to maintain your "state" (like if you are logged in and what your login information is) across an entire session of browsing a site.
PHP sets up a file (by default; this can be changed to other methods of storage) with a random wierd long number type name, and keeps information about you in that file. It puts the session name in a cookie, so that every time you request a page that cookie gets sent as well, and PHP goes and grabs your session file and puts it into the SESSION array, and updates the file with the access time.
Every now and then PHP checks all the SESSION files in its session file folder, and deletes any that have access times older than a specified amount of time (by default ~22 minutes). That’s what a "session time-out" is all about; if you were logged in and didn’t do anything for ~22 minutes, suddenly you’ll find yourself logged out.
MODx adds all sorts of goodies to that array, such as your login name, your full name, and your user ID, and PHP writes the new stuff to the file. So a script can get that information from the SESSION array without having to go to the database. But not all information about a user is put into the SESSION array by MODX, so if you wanted other information a script would have to go make database queries. Web user data is kept in five or six different tables. so the queries can get interesting.