Identify current user ID using community builder for joomla 3.3.1

738 Views Asked by At


I am using the community builder free standard with joomla 3.3.1 and I am trying to get the data from the current user, mainly his ID identifier in the user table in data base. It is because I want to use it later for read all the information of the user in the data base.

I tried with "Establishing a CB $user object" but I dont know where to write that code and how to use it exactly.

Any idea?. Thanks

1

There are 1 best solutions below

2
Lodder On BEST ANSWER

You would be best using Joomla's User Object.

To do this, you can use the following:

$user = JFactory::getUser();
echo $user->id;
echo $user->name;

For more information about the possibilities of Joomla's User Object, have a read of the following:

http://docs.joomla.org/Accessing_the_current_user_object

Update:

To import the Joomla framework, add teh following to your custom PHP files at the top:

define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define( 'JPATH_BASE', realpath(dirname(__FILE__)) );

require_once ( JPATH_BASE .'/includes/defines.php' );
require_once ( JPATH_BASE .'/includes/framework.php' );

$mainframe = JFactory::getApplication('site');

I believe line 3 is correct seeing as your PHP script is in the root folder, however if you move it to another directory, you will have to update the line 3 of the code above.

Hope this helps