How to create custom User Group programmatically i

2019-04-15 03:24发布

问题:

I am writing a custom Component in Joomla 3.x.

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.

回答1:

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.

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.