在 joomla 3 中,您可以添加自定义字段。它们保存在“_fields”下的 joomla mysql 数据库中。
我创建了一个名为“region”的新自定义字段。用户可以在他们的配置文件设置中添加一个值。所以我现在的问题是,如何通过 php 调用此自定义字段的用户值?
我知道如何调用用户的 profile 值,例如:
jimport( 'joomla.user.helper' );
$user = JFactory::getUser();
$userId = $user->id;
$userProfile = JUserHelper::getProfile( $userId );
$usercity = $userProfile->profile['city'];
那么如何调用 _field 值呢?
最佳答案
当您在管理区域(用户字段)中添加自定义字段时 您可以在默认配置文件页面中查看完整的用户配置文件
http://localhost/joomla/index.php?option=com_users&view=profile
然后检查实现。我偶然发现以这种方式访问它。
$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);
只是看看里面有什么。
只是让您知道您可以访问它。
希望这对您有所帮助。
关于php - 访问 joomla 3 中的自定义字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45218017/