1


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

rafaoc
  • 586
  • 7
  • 21
  • Where you write the code is entirely up top you. It all depends on **where** you want to use this information. I would also suggest using the Joomla User Object instead – Lodder Jul 31 '14 at 11:09
  • Hi @Lodder, I tried to use the Joomla User Object, but I cant get the id of the current user. Perhaps, do you have an exmaple code? – rafaoc Jul 31 '14 at 18:40

1 Answers1

1

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

Community
  • 1
  • 1
Lodder
  • 19,758
  • 10
  • 59
  • 100
  • I tried to write in the root folder a php file with Your name is {$user->name}, your email is {$user->email}, and your username is {$user->username}"; ?> But I get the next error Class 'JFactory' not found – rafaoc Aug 02 '14 at 18:26
  • That's because you have to import the Joomla library if you want to use Joomla code in files that don't belong to Joomla ;) I have updated my answer – Lodder Aug 02 '14 at 22:33