2011-11-03 123 views

回答

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); 
} 
+0

谢谢你的快速和正确的答复!我认为这是类似的东西? http://fuseinteractive.ca/blog/getting-started-drupal-install-profiles – Michiel

+0

如何获取数组中的权限值?一个简单的'var_dump($ perms)'? – Michiel

+0

该链接适用于Drupal 6,我想在D7中无法使用。最简单的方法是将标准配置文件复制到一个新文件夹中,然后重新命名所有文件(文件名等)并添加所需的额外代码:) – Clive