Reputation: 107
What i am trying to do is to output all user names from my joomla site. Actually i want to handle the user object. Any refference will be appreciated. Thanks
Upvotes: 0
Views: 1515
Reputation: 3406
$user =&JFactory::getUser();
if($user->id) {
//do user logged in stuff
}
else {
//do user not logged in stuff
}
Upvotes: 0
Reputation: 28755
To get object of current login user
$user = JFactory::getUser();
if(!$user->id){
// no user is logged in
}
else{
// logged in user
}
To get names of all users
$db = JFactory::getDBO();
$sql = "SELECT * FROM #__users";
$db->setQuery($sql);
$users = $db->loadObjectList();
foreach($users as $user){
echo $user->name;
}
or if you want to use user object, after above query
foreach($users as $user){
$userObj = JFactory::getUser($user->id);
}
Upvotes: 5
Reputation: 13371
If you want to access the current user object you can find the details in here :
Accessing the current user object - Joomla documentation
If you want to list all the users I would recommend you check the extension called Community Builder, there's a plugin that list all the current website users for it
Upvotes: 0