是否可以在您的D7网站的.install
-文件中编写一些代码,该文件允许您自动生成用户角色和权限?我一直是这样想的,但是现在,我想不出一个方法来做这件事。任何建议吗?
绝对:
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);
}