如何在Joomla 3.x中以编程方式创建自定义用户组? [英] How to create custom User Group programmatically in Joomla 3.x?

查看:107
本文介绍了如何在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆