how to getuser firstname and lastname

10 years 5 months ago #95626 by pgaskin
I have tried using

$user =& JFactory::getUser();
$name=$user->get('name');

to get the full name but how do I get the name in first name and last name separately, I tried

$firstname=$user->get('firstname');

but didn't work. Any clues?
10 years 5 months ago #95637 by ndee
What are you developing? CB Plugin, Joomla Plugin, Component, Module? ...

###################
SPEED UP HELP, read first: Help us help you
###################
10 years 5 months ago #95639 by krileon
Try the following.

[code:1]
$cbUser = CBuser::getInstance( USERID GOES HERE );
$firstname = $cbUser->getField( 'firstname' );
$middlename = $cbUser->getField( 'middlename' );
$lastname = $cbUser->getField( 'lastname' );
[/code:1]

Use whichever ones you're wanting. You can get any field you like.

To review details of the function look in plugin.foundation.php on line 897.

Please note this requires include of CB API if used outside of CB. Example:
[code:1]
global $_CB_framework, $ueConfig, $mainframe;

if ( defined( 'JPATH_ADMINISTRATOR' ) ) {
if ( ! file_exists( JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php' ) ) {
echo 'CB not installed!';
return;
}
include_once( JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php' );
} else {
if ( ! file_exists( $mainframe->getCfg( 'absolute_path' ) . '/administrator/components/com_comprofiler/plugin.foundation.php' ) ) {
echo 'CB not installed!';
return;
}
include_once( $mainframe->getCfg( 'absolute_path' ) . '/administrator/components/com_comprofiler/plugin.foundation.php' );
}
[/code:1]

Post edited by: krileon, at: 2009/04/20 14:41


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Templates - CBSubs - Hosting - Forge - Incubator - GroupJive
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM EST to 4:00 PM EST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
10 years 5 months ago #96718 by pgaskin
No I just want to get the first name and last name in separate and display them in PHP page.
10 years 5 months ago #96746 by krileon
pgaskin wrote:

No I just want to get the first name and last name in separate and display them in PHP page.


I just told you how.. please review my previous post.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Templates - CBSubs - Hosting - Forge - Incubator - GroupJive
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM EST to 4:00 PM EST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
10 years 3 months ago #102565 by khenn
I also am trying to get user attributes. I am using BreezingForms, and I am trying to preload text fields with user data. I have a form with a "before form" script set to the includes script you provided. Then, for the value of the text field, I have...

[code:1]<?php
$user =& JFactory::getUser();
$cbUser = CBuser::getInstance( $user->id );
return $cbUser->getField( 'city' );
?>[/code:1]

When I preview the page, I get the following error...

Fatal error: Class 'comprofilerDBTable' not found in {PATH}/administrator/components/com_comprofiler/library/cb/cb.tables.php on line 16

Do I need to include something else?

Thanks,
Kris
Moderators: beatnantkrileon
Time to create page: 0.391 seconds
Facebook Twitter Google LinkedIn