Get user type in Joomla with PHP

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.

Answers


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


Need Your Help

What are the available options when developing a decoupled, high scalable web application with server pushed events?

websocket apache-camel activemq stomp sockjs

I would like to see if someone can clarify me some concepts I still don´t get about integration of web applications. Up until now, I´ve been working with CometD and Activemq in a project that´s been

Creating Second User on Creating First User in Meteor.JS

javascript node.js meteor

How can we automatically create a second user when the user registers (the first user) from a form generated using the useraccounts:core package?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.