是否可以在D7网站的.install
文件中编写一些代码,以便您自动生成用户角色和权限?我总是如此,但是现在,我想不出办法来做到这一点
有什么建议?
答案 0 :(得分:1)
绝对:
function mymodule_install() {
// Make the new role
$role = new stdClass;
$role->name = 'new role name';
$role->weight = 3;
user_role_save($role);
// Permissions to assign to the role.
// Note these are defined in hook_permission()
$perms = array(
'access administration pages',
'view content',
'any other permission you want'
);
// Grant the permissions. This function takes care of all necessary cache resets
user_role_grant_permissions($role->rid, $perms);
}