1
是否可以在您的D7网站的.install
-文件中编写一些代码,以便您自动生成用户角色和权限?我总是这样,但现在,我想不出一个办法。
有什么建议吗?安装脚本中的自定义用户角色和权限
是否可以在您的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);
}
谢谢你的快速和正确的答复!我认为这是类似的东西? http://fuseinteractive.ca/blog/getting-started-drupal-install-profiles – Michiel
如何获取数组中的权限值?一个简单的'var_dump($ perms)'? – Michiel
该链接适用于Drupal 6,我想在D7中无法使用。最简单的方法是将标准配置文件复制到一个新文件夹中,然后重新命名所有文件(文件名等)并添加所需的额外代码:) – Clive