How to get user group id in Joomla 2.5.x?
This tutorial will explain you how to get user group id in Joomla 2.5
Step 1 :
Create a function in factory.php (root_folder/libraries/joomla/factory.php)
public static function group_id($id = null)
{
if (is_null($id))
{
$instance = self::getSession()->get('user');
if (!($instance instanceof JUser))
{
$instance = JUser::getInstance();
}
}
else
{
$current = self::getSession()->get('user');
if ($current->id != $id)
{
$instance = JUser::getInstance($id);
}
else
{
$instance = self::getSession()->get('user');
}
}
jimport( 'joomla.access.access' );
$group_id = JAccess::getGroupsByUser($instance->id, false);
return $group_id[0];
}
Step 2:
Call group_id() function from your custom component or from anywhere by using the code below
<?php
$group_id = &JFactory::group_id();
echo 'User group id is '.$group_id ;
?>
This tutorial will explain you how to get user group id in Joomla 2.5
Step 1 :
Create a function in factory.php (root_folder/libraries/joomla/factory.php)
public static function group_id($id = null)
{
if (is_null($id))
{
$instance = self::getSession()->get('user');
if (!($instance instanceof JUser))
{
$instance = JUser::getInstance();
}
}
else
{
$current = self::getSession()->get('user');
if ($current->id != $id)
{
$instance = JUser::getInstance($id);
}
else
{
$instance = self::getSession()->get('user');
}
}
jimport( 'joomla.access.access' );
$group_id = JAccess::getGroupsByUser($instance->id, false);
return $group_id[0];
}
Step 2:
Call group_id() function from your custom component or from anywhere by using the code below
<?php
$group_id = &JFactory::group_id();
echo 'User group id is '.$group_id ;
?>