Get logged in user with Smarty
Archived from the Xataface Users forum.
Gershy — Tue Dec 18, 2012 12:18 pm
Hey all, how do I use smarty to get the name of the logged in user? It would be easy if the authentication tool were included in $ENV, like $ENV.AUTHENTICATION_TOOL
then I could just do
- Code: Select all
{$ENV.AUTHENTICATION_TOOL->getLoggedInUser()->val('Name')}
But it doesn’t exist, so in lieu what’s the best way to go about this?
Gershy — Tue Dec 18, 2012 12:58 pm
figured it out; answer is easy: {$ENV.APPLICATION_OBJECT->getAuthenticationTool()} gets you to the authentication tool. The rest is simple.
Another way I figured out which I like more is in the beforeHandleRequest() function in the application delegate, you can use the following code to get the skintool;
- Code: Select all
import('Dataface/SkinTool.php'); $sTool = Dataface_SkinTool::getInstance();
and you can then insert any value you wish using the assign function. Say I want to get the “LoggedInUserName” with smarty as {$LoggedInUser} I could say
- Code: Select all
$user =& Dataface_AuthenticationTool::getInstance()->getLoggedInUser(); $sTool->assign('LoggedInName', $user->val('Name'));
shannah — Tue Dec 18, 2012 3:49 pm
Yes. That will work. An alternative is also:
{$ENV.user} To get the Dataface_Record object for the currently logged in user.
or
{$ENV.username} To get the username of the currently logged in user.
You can see most of the environment variables that are set in the Skin tool source.
http://weblite.ca/svn/dataface/core/tru … inTool.php
Steve