Hello,
when a user is logged in via WebLoginPE, I’d like to show him a page where data from a second table is gathered by a sql query based on his username. I thought I could use the user.username or view.username placeholders to put them into the query string of the snippet (WHERE username = [+user.username+] ..) but then realized, that this doesn’t work.
It seems I even can’t retrieve the username from the modx_web_users table via API as there it is combined with the password into a hash.
So do I have to store all related data I want to show in the modx_web_user_attributes_extended table?
Or what would be the best way/variable to identify a logged in user for a individual query - maybe saved zo a cookie?
May be it’s too simple for me at this moment to see the solution (as mostly in MODx), any help is appreciated -
Thanks!
-
☆ A M B ☆
- 24,524 Posts
You can get a good deal of user information from the SESSION.
http://www.sottwell.com/article-sessions.html
There are also MODx API functions,
http://wiki.modxcms.com/index.php/API:getLoginUserID and
http://wiki.modxcms.com/index.php/API:getLoginUserName if you don’t want to directly access the SESSION yourself.
-
☆ A M B ☆
- 24,524 Posts
A snippet really should "return" the desired value. While "echo" works, it can be unpredictable in where the echo output will be. Since snippet code is passed through the eval() function, it should be treated as a function and always return, even if it’s just an empty return; at the end.
Using the $modx->getLoginUserName() API function has the advantage of first making sure that the user is in fact a logged-in web user.