XF 2.0 PHP code to get age from a user object or user profile object

XFConvert

Member
I know I can get a user object like this:
PHP:
$finder = \XF::finder('XF:User');
$user = $finder->where('username', "Joe")->fetchOne();
There is no age property or date of birth.

So I can get a profile object like this:
PHP:
$profile = $user->Profile;

And that profile object has date of birth day, month, and year properties.

I know I can calculate in PHP the age but I think there is a way to do it within the XF 2 framework as a property or method. Does anyone know?
 
Have a look at XF\Entity\UserProfile, that's the class you get when calling $user->Profile. There are functions in there. If you want to optimize your code, do $finder->with('Profile') before fetching to reduce the amount of database queries.
 
Thank you Katsulynx. Pardon this newbie question: What is the best way to look at one of the classes such as that one (/src/Entity/UserProfile.php)? Just opening the PHP file itself, or is there an API showing all of the XF 2 classes and functions?
 
If you set up a development environment, you'll most likely be able to use the autocomplete functionality of your IDE. Phpstorm would be my suggestion if you're looking for a good IDE. Other than that, you'll learn the most from looking at the code, yes.
 
Top Bottom