访问joomla 3中的自定义字段 [英] Access the custom fields in joomla 3
问题描述
在joomla 3中,您可以添加自定义字段.它们保存在joomla mysql数据库的"_fields"下.
In joomla 3 you can add custom fields. They are saved in the joomla mysql database under "_fields".
我创建了一个新的自定义字段,称为区域".用户可以在其个人资料设置中添加一个值.所以我的问题是,现在如何通过php调用此自定义字段的用户值?
I´ve created a new custom field called "region". The users can add a value in their profile settings. So my question is now, how can i call the users value of this custom field via php?
我知道如何调用用户个人资料值,例如:
I know how to call the users profile values for example:
jimport( 'joomla.user.helper' );
$user = JFactory::getUser();
$userId = $user->id;
$userProfile = JUserHelper::getProfile( $userId );
$usercity = $userProfile->profile['city'];
那么如何调用 _field 值?
推荐答案
在管理区域(用户字段)中添加自定义字段时 您可以在默认个人资料页面中查看完整的用户个人资料
When you add the custom field in the admin area (user fields) You can view the full user profile in the default profile page
http://localhost/joomla/index.php?option=com_users&view=profile
这是屏幕截图
然后检查实现.我碰巧以这种方式访问它.
Then inspect the implementation. I came across accessing it this way.
$customFields = FieldsHelper::getFields('com_users.user', JFactory::getUser(), true);
// In my case there where only one additional field, so a took the 0-indexed value, you shall see in which index is the field you are searching for
$customFields[0]->value;
您也可以尝试
print_r($customFields);
只是看看里面有什么.
Just to see whats in it.
只是您知道您可以访问它.
Just so you know you can access it.
希望这会有所帮助.
这篇关于访问joomla 3中的自定义字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!