Php 访问被拒绝时Drupal重定向
我们在项目中使用一个名为“certificate”的模块。*.module文件中有一个函数包含以下内容:Php 访问被拒绝时Drupal重定向,php,drupal,drupal-7,Php,Drupal,Drupal 7,我们在项目中使用一个名为“certificate”的模块。*.module文件中有一个函数包含以下内容: function certificate_menu() { $items['node/%node/certificate'] = array( 'title' => 'Certificate', 'description' => 'Display earned certificate for this node', 'page callback'
function certificate_menu() {
$items['node/%node/certificate'] = array(
'title' => 'Certificate',
'description' => 'Display earned certificate for this node',
'page callback' => 'certificate_node_certificate',
'page arguments' => array(1),
'access callback' => 'certificate_can_access_certificate',
'access arguments' => array(1),
'file' => 'certificate.pages.inc',
'type' => MENU_LOCAL_TASK,
);
}
有一个“certificate\u can\u access\u certificate
”回调来检查用户是否有权下载证书
我现在尝试的是在回调返回false时重定向到页面“/my/other/access/denied/page/for/certificate
”
现在推荐的解决方法是什么
1) 操纵回调函数,每当它返回“False”时,我只写一个退出使用location()
在那里编码并重定向
2) 有没有办法在我自己的自定义模块中创建一个函数来实现重定向
3) 我是否必须以特殊方式操作函数certificate\u menu()
我对Drupal了解不多,所以我不知道最好的方法是什么,以及如何做到这一点 您可以在access回调中使用“drupal_goto”函数重定向
下面是一个示例,如果您添加?doredirect=true,它将从访问函数重定向
function certificate_menu() {
$items['mytestpage'] = array(
'title' => 'Certificate',
'description' => 'Display earned certificate for this node',
'page callback' => 'certificate_testpage',
'access callback' => 'certificate_access',
);
return $items;
}
function certificate_testpage() {
return 'testing!';
}
function certificate_access() {
if(isset($_GET['doredirect'])) {
drupal_goto('', array(), 301);
}
return 1;
}
另外,请注意,您需要在hook_菜单中返回$items,否则您的页面回调将无法注册