我需要限制网站的各个部分。我想通过限制对各种子路径的访问来做到这一点。路径访问模块实际上并未执行此操作。
您能否提出允许限制类似内容的任何机制:
成员区域/编辑者/ *
仅限于具有“编辑”角色的用户。
也许有办法用规则来做到这一点?我已经尝试过,但是找不到。
谢谢
参考方案
为此,您将需要一个自定义模块,这并不难。这将是症结所在:
// Implements hook_init()
function mymodule_init() {
$restrictions = mymodule_get_restrictions();
global $user;
foreach ($restrictions as $path => $roles) {
// See if the current path matches any of the patterns provided.
if (drupal_match_path($_GET['q'], $path)) {
// It matches, check the current user has any of the required roles
$valid = FALSE;
foreach ($roles as $role) {
if (in_array($role, $user->roles)) {
$valid = TRUE;
break;
}
}
if (!$valid) {
drupal_access_denied();
}
}
}
}
function mymodule_get_restrictions() {
// Obviously this data could come from anywhere (database, config file, etc.)
// This array will be keyed by path and contain an array of allowed roles for that path
return array(
'members-area/editors/*' => array('editor'),
'another-path/*' => array('editor', 'other_role'),
);
}
Drupal节点在存在时显示404 - php当某些节点存在于数据库中时,它们会显示404状态。如果您在管理页面中输入网址以编辑该节点,则还会得到404。这些节点是通过CSV文件在数据库中以自动方式创建的。我想问的是,哪个数据库字段会在节点上触发404?我已经检查了url_alias表,并且节点具有有效的条目。即:如果我在URL中输入example.com/node/512682,它将重定向到SEF U…
PHP strtotime困境 - php有人可以解释为什么这在我的服务器上输出为true吗?date_default_timezone_set('Europe/Bucharest'); var_dump( strtotime('29.03.2015 03:00', time()) === strtotime('29.03.2015 04:00…
PHP-全局变量的性能和内存问题 - php假设情况:我在php中运行一个复杂的站点,并且我使用了很多全局变量。我可以将变量存储在现有的全局范围内,例如$_REQUEST['userInfo'],$_REQUEST['foo']和$_REQUEST['bar']等,然后将许多不同的内容放入请求范围内(这将是适当的用法,因为这些数据指的是要求自…
php-casperjs获取内部文本 - php我正在为casperjs使用php包装器-https://github.com/alwex/php-casperjs我正在网上自动化一些重复的工作,我需要访问一个项目的innerText,但是我尚不清楚如何从casperjs浏览器访问dom。我认为在js中我会var arr = document.querySelector('label.input…
php:拆分字符串,直到第一次出现数字 - php我有像cream 100G sup 5mg Children 我想在第一次出现数字之前将其拆分。所以结果应该是array( array('cream','100G'), array('sup','5mg Children') ); 可以告诉我如何为此创建图案吗?我试过了list(…