如何在 Joomla 3.x 中以编程方式创建自定义用户组? [英] How to create custom User Group programmatically in Joomla 3.x?
问题描述
我正在 Joomla 3.x 中编写自定义组件.
I am writing a custom Component in Joomla 3.x.
在组件的某个点,我需要在 Joomla 的注册"组下创建一个自定义用户组.
At a certain point of the component I need to create a Custom User Group under 'Registered' group in Joomla.
在网上搜索了很多,我没有找到这个问题的解决方案.
After searching the web a lot, I found no solution of this problem.
推荐答案
您可以以编程方式将其添加到 #__usergroups
表中,确保用户组不存在;或获取 JTableUsergroup
的实例(在 libraries/joomla/table/usergroup.php
中声明).由于它扩展了 JTable
,您可以使用它的 save()
方法,传递一个包含您希望存储的值的数组.
You can add it to the #__usergroups
table programmatically, ensuring the user group is not there already; or get an instance of JTableUsergroup
(declared in libraries/joomla/table/usergroup.php
). Since it extends JTable
you can use its save()
method, passing an array with the values you wish to store.
然后为了获得正确的 lft 和 rgt 值,您需要调用 JTableUsergroup
上的 rebuild()
方法.
Then in order to have proper lft and rgt values, you need to invoke the rebuild()
method on JTableUsergroup
.
请确保以编程方式添加它确实是必要的,这可能会导致已经大量使用用户组的网站出现问题.
Please ensure adding it programmatically is really necessary, it may cause issues on sites that already make heavy use of usergroups.
这篇关于如何在 Joomla 3.x 中以编程方式创建自定义用户组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!