php - 访问 joomla 3 中的自定义字段

标签 php mysql joomla

在 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

这是截图 enter image description here

然后检查实现。我偶然发现以这种方式访问​​它。

$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);

只是看看里面有什么。

只是让您知道您可以访问它。

enter image description here

希望这对您有所帮助。

关于php - 访问 joomla 3 中的自定义字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45218017/

相关文章:

php - 如何找出需要在 Symfony 4 中添加的 use 语句?

c# - 如何通过MySqlReader C#读取多个请求

mysql - 如何构建包含翻译和同义词的词典表

php - UTF-8贯穿始终

mysql - 我如何将社区构建器从 joomla 1.0 迁移到 joomla2.5

css - 将 CSS 添加到 Joomla 3 模板管理区域

php - Ajax PHP MySQLI - 获取最后更新的行,但未准备好文档

php - 在 MySQL 的 WHERE EXISTS 查询中使用选定的列

joomla - Joomla 3-如何使用较新版本覆盖jQuery?

php - 如何显示由 $_GET 函数定义的先前隐藏的 div