I am working on a simple game to add to my joomla site, done in html/javascript. I want to be able to track user scores, I figure the easiest way to do that is to have the scores saved by username... but I can't figure out how to have joomla provide the javascript with the username?
+1
A:
You can get all of the information about the currently logged in user from the JUser
object. To get it and store it in a variable named $user
, use this code:
$user = JFactory::getUser();
From this object, you can get the username, id, email address, and other information about the user:
<input type="hidden" value="<?php echo $user->username ?>" id="username" />
<input type="hidden" value="<?php echo $user->id ?>" id="id" />
<input type="hidden" value="<?php echo $user->email ?>" id="email" />
Then you can call JavaScript to extract the information from HTML. Once you're ready to record the high score, you could make an AJAX-style call pointing to a Joomla component.
jlleblanc
2010-03-01 21:53:27