Get user type in Joomla with PHP
Question
I'm trying to get a logged in users type (eg super admin, registered). I've tried this code:
$user =& JFactory::getUser();
$curref = $user->usertype();
Which gives a function not found error. What is the correct way to get the user type name, without a db query if possible.
Solution
You just need to treat usertype as a member, not a method.
$type = $user->usertype;
Documentation: http://docs.joomla.org/Accessing_the_current_user_object
You can take a look at the $user object structure by doing a var_dump. Try this, and inspect the output:
var_dump( $user );
So if you want to iterate over the groups array, you could do the following:
$groupIDs = array();
foreach( $user->groups as $groupID ){
$groupIDs[] = $groupID;
}
var_dump( $groupIDs );
You can also use some joomla methods to return the groups in different ways. You may want to check out this forum thread: http://forum.joomla.org/viewtopic.php?t=530721
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow